最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

dismissViewControllerAnimated和dismissModalViewControllerAnimated之间的区别和联系

iOS crifan 2927浏览 0评论

在折腾:

参考教程开发iOS的第二个app:Storyboards – BirdWatching

中,参考:

Your Second iOS App – Edit the Master Scene and Connect It to the Add Scene

中看到两个函数dismissViewControllerAnimated和dismissModalViewControllerAnimated,想要搞清楚其两者的区别。

然后就去找了找,到Mac官网的iOS dev lib:

http://developer.apple.com/library/ios/navigation/

中搜到了:

UIViewController Class Reference

其中有详细的函数的解释:

dismissModalViewControllerAnimated:

Dismisses the view controller that was presented by the receiver. (Deprecated. Use dismissViewControllerAnimated:completion: instead.)

– (void)dismissModalViewControllerAnimated:(BOOL)animated

Parameters
animated

If YES, this method animates the view as it’s dismissed; otherwise, it does not. The style of animation is determined by the value in the modalTransitionStyle property of the view controller being dismissed.

Discussion

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, however, it automatically forwards the message to the presenting view controller.

If you present several view controllers in succession, and thus build a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

If you want to retain a reference to the receiver’s presented view controller, get the value in the modalViewController property before calling this method.

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In

UIViewController.h

dismissViewControllerAnimated:completion:

Dismisses the view controller that was presented by the receiver.

– (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion

Parameters
flag

Pass YES to animate the transition.

completion

A block called after the view controller has been dismissed.

Discussion

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller.

If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

If you want to retain a reference to the receiver’s presented view controller, get the value in the presentedViewController property before calling this method.

The completion handler is called after the viewDidDisappear: method is called on the presented view controller.

Availability
  • Available in iOS 5.0 and later.
Declared In

UIViewController.h

【总结】

可见,dismissModalViewControllerAnimated是iOS 5.0以后就废弃的,取而代之的是dismissViewControllerAnimated。

即,以后再使用这两个函数的时候,尤其是iOS 5.0后,一定要使用dismissViewControllerAnimated,而不要再用dismissModalViewControllerAnimated了

转载请注明:在路上 » dismissViewControllerAnimated和dismissModalViewControllerAnimated之间的区别和联系

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
85 queries in 0.173 seconds, using 22.06MB memory