Presenting a modal view controller only after another one has been dismissed

…衆ロ難τιáo~ 提交于 2020-01-01 23:13:04

问题


I can't just do

[myViewController dismissModalViewControllerAnimated:YES];
[myViewController presentModalViewController:nextModalViewController animated:YES];

one after the other, because then the two animation blocks try to affect the same references simultaneously and things break badly.

So what I need to do is make the latter call only after the first animation has finished. But there's no UIViewControllerDelegate method like didDismissModalViewController. What should I do?


回答1:


What's wrong with just subclassing the view controller (if you haven't already) and doing this:

 - (void) viewDidDisappear: (BOOL) animated
 {
     [super viewDidDisappear: animated];


     [myViewController presentModalViewController:nextModalViewController animated:YES];
 }

I'm not sure how you are handling your references to the view controllers, but the point I'm trying to make is just catch the viewDidDisappear for the model view controller that is sliding off.




回答2:


It's a bit hacky (ok, maybe a lot hacky), but you could simply present the second one after a fixed delay:

[myViewController performSelector:@selector(showSecondModalView) withObject:nil afterDelay:0.5];

(or whatever the animation duration turns out to be).



来源:https://stackoverflow.com/questions/1208299/presenting-a-modal-view-controller-only-after-another-one-has-been-dismissed

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