presentedViewController和presenti
2021-12-08 本文已影响0人
大树和小鱼
Summary
The view controller that presented this view controller.
Declaration
var presentingViewController: UIViewController? { get }
Discussion
When you present a view controller modally (either explicitly or implicitly) using the present(_:animated:completion:) method, the view controller that was presented has this property set to the view controller that presented it. If the view controller was not presented modally, but one of its ancestors was, this property contains the view controller that presented the ancestor. If neither the current view controller or any of its ancestors were presented modally, the value in this property is nil.
Open in Developer Documentation
Summary
The view controller that is presented by this view controller, or one of its ancestors in the view controller hierarchy.
Declaration
var presentedViewController: UIViewController? { get }
Discussion
When you present a view controller modally (either explicitly or implicitly) using the present(_:animated:completion:) method, the view controller that called the method has this property set to the view controller that it presented. If the current view controller did not present another view controller modally, the value in this property is nil.
Open in Developer Documentation
一句话解释:
A presentViewController B 后,a.presentedViewController就是b,b.presentingViewController就是a,over。
我们判断当前页面是否是present进来的就可以用presentingViewController
func isPresent() -> Bool {
return navigationController?.presentingViewController != nil
}
也可以通过
navigationController?.topViewController == self
来判断是否是presnet出来的,如果topViewControler == self,则代表是push出来的,在navigationController的最上层。。false则是presnet来的