Hi again..
I'm trying to animate with a UIImageView.
using this.
called from this inside:
So my sticker appear ok but the animating ones are too big and not in the right spot, how do I scale them to match the view / drawInRect image.
P.S sorry for the messy code..
thank
I'm trying to animate with a UIImageView.
using this.
Code:
-(void)animateNewStampImage:(UIImage *)myStamp ToHere:(CGRect)finalRect
{
CGRect bounds = [self bounds];
CGPoint topLeftCorner;
CGPoint centre;
topLeftCorner.x = bounds.origin.x + bounds.size.width ; // in percentage of screen size //
topLeftCorner.y = bounds.origin.y + bounds.size.height; // in percentage of the screen size //
centre.x = bounds.origin.x + bounds.size.width / 2; // in percentage of screen size //
centre.y = bounds.origin.y + bounds.size.height/ 2; // in percentage of the screen size //
/*
UIImage* animStampImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
*/
UIImageView *myNewStamp = [[[UIImageView alloc]initWithImage:[myStamp stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0]]retain];
myNewStamp.bounds = CGRectMake(0,0,bounds.size.width,bounds.size.height);
//[myNewStamp setFrame:CGRectMake(0,0,bounds.size.width,bounds.size.height)];
//[myNewStamp setBounds:CGRectMake(0,0,bounds.size.width,bounds.size.height)];
//NSLog(@"animating Stamp");
//UIImageView * myNewStamp = [[UIImageView alloc] initWithImage:myStamp];
//[myNewStamp setFrame:CGRectMake(0,0,bounds.size.width,bounds.size.height)];
CABasicAnimation *opacityAnimm = [CABasicAnimation animationWithKeyPath:@"opacity"];
CABasicAnimation *scaleAnimm = [CABasicAnimation animationWithKeyPath:@"transform"];
CABasicAnimation *positionAimm = [CABasicAnimation animationWithKeyPath:@"position"];
scaleAnimm.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1,1,1.0)];
scaleAnimm.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(.1,.1,1.0)];
scaleAnimm.removedOnCompletion = YES;
CGPoint positionStampNew = finalRect.origin;
//positionAimm.fromValue =[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(positionStampNew.x,positionStampNew.y,0)];
//positionAimm.fromValue =[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(positionStampNew.x,positionStampNew.y,0)];
positionAimm.fromValue =[NSValue valueWithCGPoint:positionStampNew];
//NSLog(@" x: %f y: %f",finalRect.origin.x,finalRect.origin.y);
CGPoint sumRandomPosition = CGPointMake(arc4random()%20+finalRect.origin.x,arc4random()%20+finalRect.origin.y);
positionAimm.toValue = [NSValue valueWithCGPoint:sumRandomPosition];
//positionAimm.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeTranslation(sumRandomPosition.x,sumRandomPosition.y,0)];
positionAimm.removedOnCompletion = YES;
NSLog(@" x: %f y: %f to X:%f Y:%f",positionStampNew.x,positionStampNew.y,sumRandomPosition.x,sumRandomPosition.y);
opacityAnimm.toValue = [NSNumber numberWithFloat:0.6];
opacityAnimm.fromValue = [NSNumber numberWithFloat:0.1];
opacityAnimm.removedOnCompletion = YES;
CAAnimationGroup *animGroupp = [CAAnimationGroup animation];
animGroupp.animations = [NSArray arrayWithObjects:opacityAnimm,scaleAnimm,positionAimm,nil];
animGroupp.delegate = self;
animGroupp.duration = 1.4;
//[UIView setAnimationDidStopSelector:@selector(stopButton)];
// [myNewStamp layer] //
//
[[myNewStamp layer] addAnimation:animGroupp forKey:@"newStamAnim"];
[self addSubview:myNewStamp];
[myNewStamp release];
}
called from this inside:
Code:
- (void)drawRect:(CGRect)rect {
// stampPost is a CGPoint read from an array of objects
// stampSize is a CGSize read from an array of objects --- both are correct when NSLogged - printed
if (newStampMarker){
CGRect newStampRec = CGRectMake(stampPost.x,stampPost.y, stampSize.width, stampSize.height);
uiimage = [UIImage imageNamed:@"SmileyStampYellow.png"];
[self animateNewStampImage:uiimage ToHere:newStampRec];
}
// also using this to draw non new stamps works fine //
[uiimage drawInRect:CGRectMake(stampPost.x,stampPost.y, stampSize.width, stampSize.height)];
// and I add it to the View with this. //
UIImage* blendedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *stampOverlay = [[UIImageView alloc] initWithImage:blendedImage];
[blendedImage release];
//[uiimage release];
[stampOverlay setFrame:CGRectMake(0,0,bounds.size.width,bounds.size.height)];
[stampOverlay setAlpha:STAMPBASE];
[self addSubview:stampOverlay];
}
So my sticker appear ok but the animating ones are too big and not in the right spot, how do I scale them to match the view / drawInRect image.
P.S sorry for the messy code..
thank
Last edited: