我想使用动画制作图像,点击按钮开始并在5秒后停止 . 我使用此代码 .
-(IBAction) btnClicked{
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 6;
fullRotation.repeatCount = 1e100f;
fullRotation.delegate = self;
[imgView.layer addAnimation:fullRotation forKey:@"360"];
[imgView.layer setSpeed:3.0];
}
使用此代码动画启动但我不知道如何在5秒后停止此动画 .
1 回答
甚至不处理CoreAnimation . 我认为这可以通过UIView动画完成,它更容易编程 . 查看UIView文档并尝试块动画(假设ios4.0 . 如果没有,请使用旧版本) .
请查看http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html%23//apple_ref/doc/uid/TP40009503-CH6-SW1以获取有关UIView动画的文档 . 设置transform属性以使用CGAffineTransformMakeRotation进行旋转
这是一个基于UIView的动画旋转:
}