iPhone - Detect the end of the animation

2019-02-25 13:25发布

How can I detect the end of the animation of a modal view (when I do a dismiss)? (I'm talking about MFMailComposeViewController which is not created by myself...)

Thanks

4条回答
劳资没心,怎么记你
2楼-- · 2019-02-25 13:48

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
查看更多
叛逆
3楼-- · 2019-02-25 13:49

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.

查看更多
【Aperson】
4楼-- · 2019-02-25 13:59

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?)

查看更多
唯我独甜
5楼-- · 2019-02-25 14:00

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.

查看更多
登录 后发表回答