使用 CABasicAnimation iPhone 启动和停止动画
我想对图像使用动画,在单击按钮时启动并在 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 秒后停止此动画。
I want to use animation for image, start on button clicked and stop after 5 seconds.I use this code.
-(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];
}
with this code animation is started but i don't know how to stop this animation after 5 seconds.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
甚至不处理 CoreAnimation。我认为这可以通过 UIView 动画来实现,它更容易编程。查看
UIView
文档并尝试块动画(假设 iOS 4.0。如果没有,请使用旧样式)。看看 此处有关
UIView
动画的文档。设置transform
属性以使用CGAffineTransformMakeRotation
进行旋转。这是一个基于
UIView
的动画旋转:Don't even deal with
CoreAnimation
. I think this can be do this withUIView
animations, which are easier to program. Look atUIView
documentation and try the block animations (assuming iOS 4.0. if not, use older style).Look here for the docs on
UIView
animations. Set thetransform
property to do the rotation usingCGAffineTransformMakeRotation
.Here is a
UIView
based animated rotation: