iPhone - 检测动画的结尾
如何检测模态视图动画的结束(当我关闭时)? (我说的是 MFMailComposeViewController 这不是我自己创建的......)
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的模态视图控制器有一个
-viewDidDisappear:
方法,每当视图从屏幕上删除时就会自动调用该方法。您可以在模态视图控制器中重写此方法来执行您喜欢的操作。另外,您可能需要考虑在视图控制器中实现
-viewDidAppear:
方法,该视图控制器的视图会因模态视图消失而显示。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.您可以子类化 MFMailComposeViewController 并重载其
-viewDidDisappear:
。You can subclass MFMailComposeViewController and overload its
-viewDidDisappear:
.我需要在关闭模态视图后做一些事情,并且只有当确定模态视图确实消失(已完全解除分配)时。所以 viewDidDisappear 和模态视图中的朋友对我来说还太早了。
我发现最简单的方法就是用 NSTimer 延迟我的代码。当模态视图调用其委托并且委托调用删除模态视图时,它还会将要在模态视图消失时运行的代码排队。时间大约是 300 毫秒或 400 毫秒。 (有没有办法从某处检索实际时间?)
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?)
通常,要在动画完成时收到通知,您可以通过发送 setAnimationDelegate: 到 UIView 类。
当使用
[someVC DismissModalViewControllerAnimated:YES]
关闭 VC 时,您无法设置动画委托,但如果您改为发送 NO 并为 VC 视图执行自己的动画,您可以 设置委托并在动画完成时收到通知。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.