[英]UIView animateWithDuration start over
I have a simple question :) but I'm asking to gain benefits from awesome programmers in stackoverflow community. 我有一个简单的问题:),但我想从Stackoverflow社区的优秀程序员中受益。
I'm using UIView.animateWithDuration in my source view in viewDidAppear the animation start as follow by calling startTheStory(): 我在viewDidApp的源代码视图中使用UIView.animateWithDuration通过调用startTheStory()如下所示显示动画开始:
override func viewDidAppear(animated: Bool) {
if !animate {
startTheStory()
}
}
Then the view transaction with the destination view by using custom segue. 然后,使用定制segue将视图事务与目标视图合并。
My problem is when the transaction start the animation in the source view start over so I tried to stop it by the following code: 我的问题是事务在源视图中重新启动动画时重新开始,因此我尝试通过以下代码停止动画:
override func viewWillDisappear(animated: Bool) {
animate = true
self.view.layer.removeAllAnimations()
}
But it doesn't work. 但这是行不通的。
Also I tried in prepareForSegue() but it doesn't work. 我也尝试在prepareForSegue()中,但是它不起作用。
Any idea? 任何想法?
Thanks 谢谢
remove this line self.view.layer.removeAllAnimations()
删除此行
self.view.layer.removeAllAnimations()
and add these lines 并添加这些行
[CATransaction begin]
[_backgroundView.layer removeAllAnimations]
[CATransaction commit]
[CATransaction flush]
Do remember to import QuartzCore/QuartzCore.h
记得导入
QuartzCore/QuartzCore.h
Reason why your animation stars over is because 您的动画出演的原因是
if !animate {
startTheStory()
}
is always executed in the viewDidAppear method, because the "animate" is set to false each time the view is about to paint again on the screen. 总是在viewDidAppear方法中执行,因为每次视图将再次在屏幕上绘制时,“动画”都设置为false。 Setting the "animate" to "True" in viewWillDisappear will get reset again to "False" when the viewDidAppear is called.
当调用viewDidAppear时,将viewWillDisappear中的“动画”设置为“真”将再次重置为“假”。 So try to keep the "animate" var global in app delegate and set the value this should do the trick.
因此,尝试在应用程序委托中保持“ animate” var全局,并设置该值即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.