UIView 块动画将视图从左到右和从后到左移动
我不想对形状为箭头的视图进行动画处理,我希望它从左到右、从左到右等进行动画处理。
下面的代码不起作用,我猜我需要一条路径,但是不知道如何在 UIView 块动画中做到这一点。
[UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionRepeat animations:^{
controller.view.frame = frame1;
controller.view.frame = frame2;
} completion:^(BOOL finished) {
}];
I wan't to animate a view that's shaped as an arrow, and I want it to animate from left to right, left to right and so on..
This code below is not working, I'm guessing I need a path, but don't know how to do that in a UIView block animation.
[UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionRepeat animations:^{
controller.view.frame = frame1;
controller.view.frame = frame2;
} completion:^(BOOL finished) {
}];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
UIViewAnimationOptionAutoreverse
选项,尝试下面的代码:它将重复从右到左,从左到右,......顺利地移动。
You can use
UIViewAnimationOptionAutoreverse
option, try the code below:It'll repeat move from right to left, left to right, ... smoothly.
假设
frame1
是重复之前的起始位置,frame2
是重复之前的结束位置。问题是动画是在运行循环结束时计算的,因此忽略了frame1,视图只是移动到frame2。如果将
frame1
的设置移到块之外,那么它应该可以正常工作。如果您希望动画向后和向前播放,则需要使用UIViewAnimationOptionAutoreverse
使其autoreverse
Assuming that
frame1
is the starting position andframe2
is the end position before repeat.The problem is that the animation is calculated at the end of the runloop therefore the
frame1
is ignored and the view is simply moved toframe2
. If you move the setting offrame1
outside of the block then it should work fine. If you want the animation to play back and forward you will need to make itautoreverse
withUIViewAnimationOptionAutoreverse