iPhone - Detect the end of the animation

旧时模样 提交于 2019-12-01 21:29:23

Your modal view controller has a -viewDidDisappear: method that is automatically invoked whenever the view is removed from the screen. You can override this method in your modal view controller to do whatever you like.

Also, you may want to consider implementing the -viewDidAppear: method in the view controller whose view gets revealed by your modal view disappearing.

You can subclass MFMailComposeViewController and overload its -viewDidDisappear:.

@interface MyCtrler : MFMailComposeViewController
@end
@implementation MyCtrler
-(void)viewDidDisappear:(BOOL)animated {
   [super viewDidDisappear:animated];
   // do anything you like
}
@end

I needed to do something after dismissing a modal view, and only when it is sure that the modal view is really gone (been completely dealloc-ed). So viewDidDisappear and its friends in the modal view were too early for me.

The easiest I found was to just delay my code with a NSTimer. When modal view calls its delegate and the delegate invokes removing the modal view, it also queues up the code to be run when the modal view is gone. The timing was something like 300ms or 400ms. (Is there a way to retrieve the actual timing from somewhere?)

Normally to be notified when an animation is complete you set a delegate by sending setAnimationDelegate: to the UIView class.

When a VC is dismissed using [someVC dismissModalViewControllerAnimated:YES] you can't set the animation delegate, but if you send NO instead and do your own animation of the VC's view you can set the delegate and be notified when the animation is completed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!