我有简单的旋转转换,结合alpha,它在第一次调用时完美运行,但第二次旋转不会发生(用户通过点击屏幕启动此动画)。
这是我的基本动画功能:
- (void) animateMe:(UIImageView *)myImage delay:(NSTimeInterval)dly
{
[UIView animateWithDuration:1.0
delay:dly
options:UIViewAnimationOptionAutoreverse
animations:^(void){
myImage.alpha = 1.0;
myImage.transform = CGAffineTransformMakeRotation(180.0);
}
completion:^(BOOL finished) {
myImage.alpha = 0.0;
}];
}
问题是第二次要
旋转视图时,它已经旋转了 180 度,并且行:
myImage.transform = CGAffineTransformMakeRotation(180.0);
相当于:
myImage.transform = myImage.transform;
所以你应该做这样的事情:
myImage.transform = CGAffineTransformRotate(myImage.transform, 180.0);
<小时 />请注意,文档说旋转角度应以弧度为单位,而不是度数。所以你可能应该使用M_PI
而不是180.0
。
另外,请注意,文档说UIViewAnimationOptionAutoreverse
必须与UIViewAnimationOptionRepeat
结合使用。
UIViewAnimationOptionAutoreverse
前后运行动画。必须与 UIViewAnimationOptionRepeat 选项结合使用。