Ala*_*ore 2 animation image-rotation cgaffinetransform ios5
我有简单的旋转变换,结合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;
}];
}
Run Code Online (Sandbox Code Playgroud)
问题是,第二次要旋转视图时,它已经旋转180度并且行:
myImage.transform = CGAffineTransformMakeRotation(180.0);
Run Code Online (Sandbox Code Playgroud)
相当于:
myImage.transform = myImage.transform;
Run Code Online (Sandbox Code Playgroud)
所以你应该这样做:
myImage.transform = CGAffineTransformRotate(myImage.transform, 180.0);
Run Code Online (Sandbox Code Playgroud)
请注意,文档说旋转角度应该是弧度而不是度.所以你可能应该使用M_PI而不是180.0.
另请注意,文档说UIViewAnimationOptionAutoreverse 必须与之结合使用UIViewAnimationOptionRepeat.
UIViewAnimationOptionAutoreverse
向后和向前运行动画.必须与UIViewAnimationOptionRepeat选项结合使用.