我有一个UIView对象。当我改变全局可变角度时,它会旋转。我有一个功能从它的父视图中移除这个UIView并重新绘制它。我添加了一个按钮。当用户按下这个按钮时,我需要启动一个动画。在每一步中,我都需要改变角度并调用重绘函数。我希望看到的效果是我的视图在旋转。下面是代码:
-(IBAction)animate:(id)sender
{
NSLog(@"animate: called");
[UIView animateWithDuration:0.7
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{
angle=angle+5.0;
if (angle>360)
{
angle=angle-360;
}
else if(angle<0)
{
angle=angle+360;
};
NSLog(@"inner angle: %g", angle);
[self transform]; //this is my redraw function. it redraws my view depending on global variable value angle.
}
completion:NULL];
NSLog(@"finalAngle: %g", angle);
}
为什么这个动画不能正常工作?
UIView动画只支持以下属性
@property frame
@property bounds
@property center
@property transform
@property alpha
@property backgroundColor
@property contentStretch
你必须执行动画与核心动画框架
您可以动画转换属性。然而,使用transform属性执行旋转比使用CA框架要复杂得多。我发现这个帖子很有帮助:UIView无限360度旋转动画?