我在执行旋转动画之前先执行UIImageView的旋转:
// rotate to the left by 90 degrees
someView.transform = CGAffineTransformMakeRotation((-0.5)*M_PI);
然后将视图上的旋转调整180度......但似乎它是从原始位置开始旋转图像,就像它最初没有旋转一样。
- (void)rotateIndicatorToAngle: (UIView *)view angle: (NSNumber *)angleInDegrees
{
CALayer *layer = view.layer;
CGFloat duration = 5.0;
CGFloat radians = [self ConvertDegreesToRadians: [angleInDegrees floatValue]];
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: radians];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1.0;
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.fillMode = kCAFillModeForwards;
rotationAnimation.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseOut];
[layer addAnimation: rotationAnimation forKey: @"rotationAnimation"];
}
是什么给出了?
答案 0 :(得分:4)
rotationAnimation.cumulative = YES;
您是否尝试过使用rotationAnimation.additive = YES;
而不是累积?
答案 1 :(得分:2)
您可以使用UIView
中的类方法轻松为视图设置动画:
[UIView beginAnimation: @"Rotate" context: nil];
[UIView setAnimationDuration: 5.0f];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
CGFloat radians = [self ConvertDegreesToRadians: [angleInDegrees floatValue]];
view.transform = CGAffineTransformMakeRotation(radians);
[UIView commitAnimation];
这就是我大部分时间都在使用的,不需要使用图层。
更新:我的意思是,我发现在这种情况下不使用图层更容易,对使用图层没有贬义价值。