调用dismissModalViewController后,CALayer动画出现问题
我有一个视图控制器,其动画在视图控制器出现时运行。 每次视图控制器出现时,动画都应该重置到某个位置并再次重播动画。 viewWillAppear 重置动画子视图的位置。 viewDidAppear 运行 CALayer 动画。 它第一次工作得很好,但是当我呈现一个模态视图控制器并关闭它时,动画视图控制器的子视图会在动画的最终位置出现一小段时间,然后重置到开始动画的原始位置。 我确保 viewWillAppear 被调用,它应该重置动画子视图的位置。
欢迎任何建议。 感谢您的提前。
I have a view controller with animation that run when the view controller appears.
Every time the view controller appears the animation should reset to certain position and replay the animation again.
The viewWillAppear resets the position of the animated subviews.
The viewDidAppear runs CALayer animation.
It works good first time, but when I present a modal view controller and dismiss it, the animated view controller's subviews appear for a small time in the final position of the animation, then it resets to the original position where it starts the animation.
I made sure viewWillAppear is called where it should reset the animated subviews' positions.
Any suggestions are welcome.
Thanks for advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的直觉是正确的:当你关闭模态视图控制器时,底层视图会再次显示,并且它的控制器会收到
viewWillAppear
/viewDidAppear
消息。您必须解决此问题的一种可能性是重置 viewDidLoad 中的动画,该动画在视图加载到内存中后调用(如果视图未卸载,则仅调用一次)。事实上,这个方法用于完成视图初始化,并且似乎是放置动画重置的正确位置。
如果此解决方案不适合您的应用程序(我不知道您总体上在做什么)并且您需要在 viewWillAppear 中进行重置,那么您可以考虑在控制器中设置一个标志显示模态视图,所以您知道,下次控制器收到
viewWillAppear
时,它是在模态视图关闭之后出现的,并且您不执行重置。我并不是建议你这样做,这非常老套而且不太有弹性,只是说,如果你不能接受其他解决方案。更好地重新设计您的应用,以便在viewWillAppear
中不需要重置。I think you intuition is correct: when you dismiss the modal view controller, the underlying view is displayed again and it controller receives the
viewWillAppear
/viewDidAppear
messages.One possibility you have to fix this is resetting the animation in
viewDidLoad
, which is called once the view has been loaded in memory (just once if the view is not unloaded). Indeed this method is used to complete the view initialization and seems the right place where to put thereset
of the animation.If this solution is not right for your app (I have no idea about what you are doing overall) and you need to have the reset in the
viewWillAppear
, you could think of setting a flag in your controller when the modal view is displayed, so you know, the next time your controller receives theviewWillAppear
that it comes after the dismiss of the modal view and you don't do the reset. I am not suggesting you to do this, which is pretty hacky and not very resilient, just saying, if you cannot accept the other solution. Much better redesigning your app so that reset is not required inviewWillAppear
.