【发布时间】:2014-09-15 12:20:48
【问题描述】:
我有这个代码:
-(void)animationLoop{
CGPoint oldPoint = CGPointMake(myCircleUIView.frame.origin.x, myCircleUIView.frame.origin.y);
[UIView animateWithDuration:1.0
animations: ^{ myCircleUIView.frame = CGRectMake(myCircleUIView.frame.origin.x + [self randomFloatingGenerator], myCircleUIView.frame.origin.y + [self randomFloatingGenerator], myCircleUIView.frame.size.width, myCircleUIView.frame.size.height); }
completion:
^(BOOL finished) {
[UIView animateWithDuration:1.0
animations:^{ myCircleUIView.frame = CGRectMake(oldPoint.x, oldPoint.y, myCircleUIView.frame.size.width, myCircleUIView.frame.size.height);}
completion:
^(BOOL finished) {[self animationLoop];}];
}];
}
但我试图在与动画交互时停止动画,但[myCircleUIView.layer removeAllAnimations]; 不会完成这项工作,有什么建议吗?
【问题讨论】:
-
我相信2018年最好的办法就是使用UIViewPropertyAnimator。与此相比,旧的解决方案似乎是丑陋的黑客。
标签: ios animation uiview uiviewanimation