1

I'm new in iOS development. I'm creating a Keyframe animation for rotating the image.The image was successfully rotated in forward.I want to rotate the image in full and full backward.

This is my code.

UIImageView *tempView = [[UIImageView alloc] initWithFrame:CGRectMake(28,158,133,133)];
tempView.image = [UIImage imageNamed:@"1_03.png"];
[self.view addSubview:tempView];

const NSUInteger rotations = 1;
const NSTimeInterval duration  = 4.0f;

CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
CGFloat touchUpStartAngle = 0;
CGFloat touchUpEndAngle = (M_PI);
CGFloat angularVelocity = (((2 * M_PI) * rotations) + M_PI) / duration;
anim.values = @[@(touchUpStartAngle), @(touchUpStartAngle + angularVelocity * duration)];
anim.duration = duration;
anim.delegate = self;
anim.repeatCount = INFINITY;
[tempView.layer addAnimation:anim forKey:@"animation"];

tempView.transform = CGAffineTransformMakeRotation(touchUpStartAngle +     (touchUpEndAngle));

How to do this.

4

2 回答 2

3

尝试这个。

UIImageView *tempView = [[UIImageView alloc] initWithFrame:CGRectMake(28,158,133,133)];
tempView.image = [UIImage imageNamed:@"1_03.png"];
[self.view addSubview:tempView];

const NSUInteger rotations = 1;
const NSTimeInterval duration  = 4.0f;

CAKeyframeAnimation *anim = [CAKeyframeAnimation      animationWithKeyPath:@"transform.rotation"];
CGFloat touchUpStartAngle = 0;
CGFloat touchUpEndAngle = (M_PI);
CGFloat angularVelocity = (((2 * M_PI) * rotations) + M_PI) / duration;
anim.values = @[@(touchUpStartAngle), @(touchUpStartAngle - angularVelocity * duration)];
anim.duration = duration;
anim.delegate = self;
anim.repeatCount = INFINITY;
[tempView.layer addAnimation:anim forKey:@"animation"];

tempView.transform = CGAffineTransformMakeRotation(touchUpStartAngle +     (touchUpEndAngle));
于 2013-06-20T10:01:51.123 回答
1

尝试这个

CGFloat touchUpStartAngle = 0;
CGFloat touchUpEndAngle = (M_PI);
CGFloat angularVelocity = (((2 * M_PI) * rotations) + M_PI) / duration;
anim.values = @[@(touchUpStartAngle), @(touchUpStartAngle - angularVelocity * duration)];
于 2013-06-20T10:09:42.283 回答