开发者

After dismissModalViewController called, problems with CALayer animation

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 ru开发者_开发问答ns 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.


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 the reset 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 the viewWillAppear 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 in viewWillAppear.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜