views:

353

answers:

1

I am using this code for rotate animation:

CABasicAnimation *spinAnimation = [CABasicAnimation
                                   animationWithKeyPath:@"transform.rotation.z"];
spinAnimation.fromValue =[NSNumber numberWithFloat:0];
spinAnimation.toValue = [NSNumber numberWithFloat:3.30];
spinAnimation.duration =2;  
[imgArrow.layer addAnimation:spinAnimation forKey:@"spinAnimation"];

In this code imageview's bottom point is not fixed. I want to set up the image such that it rotates from a fixed point on the bottom of the image (like a speedometer).

Can you help me with this?

A: 

Try something like this:

NSString *path = [[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"];
UIImage *img = [UIImage imageWithContentsOfFile:path];
CGImageRef image = img.CGImage;
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSaveGState(context);

CGContextTranslateCTM(context, 365.0, 305);
CGContextRotateCTM(context, angle); 
touchRect = CGRectMake(-10.0, -5.0, img.size.width, img.size.height); // (-10.0, -5.0) - arrow's rotation center
CGContextDrawImage(context, touchRect, image); 

CGContextRestoreGState(context);
evgen_povt
touchRect is undeclared . How do I declare it ?
CGRect touchRect;
evgen_povt