【iOS】判断viewcontroller 来源(展示出来)的4个方法

来源:互联网 发布:淘宝怎么换购产品 编辑:程序博客网 时间:2024/06/13 07:02
isMovingFromParentViewController / isMovingToParentViewController :适应于container 和 content viewcontroller 之间。例如:addChildViewController方法,navigationController 中的push 和pop。

isBeingPresented / isBeingDismissed :适应于present 和 presented viewcontroller 之间。presentViewController: animated: completion方法。

【官方资料】
Determining Why a View’s Appearance Changed

Occasionally, it can be useful to know why a view is appearing or disappearing. For example, you might want to know whether a view appeared because it was just added to a container or whether it appeared because some other content that obscured it was removed. This particular example often appears when using navigation controllers; your content controller’s view may appear because the view controller was just pushed onto the navigation stack or it might appear because controllers previously above it were popped from the stack.

The UIViewController class provides methods your view controller can call to determine why the appearance change occurred. Table 5-1 describes the methods and their usage. These methods can be called from inside your implementation of the viewWillAppear:, viewDidAppear:, viewWillDisappear: and viewDidDisappear: methods.

Table 5-1 Methods to call to determine why a view’s appearance changed
isMovingFromParentViewController
You call this method inside your viewWillDisappear: and viewDidDisappear: methods to determine if the view controller’s view is being hidden because the view controller was removed from its container view controller.

isMovingToParentViewController
You call this method inside your viewWillAppear: and viewDidAppear: methods to determine if the view controller’s view is being shown because the view controller was just added to a container view controller.


isBeingPresented
You call this method inside your viewWillAppear: and viewDidAppear: methods to determine if the view controller’s view is being shown because the view controller was just presented by another view controller.

isBeingDismissed
You call this method inside your viewWillDisappear: and viewDidDisappear: methods to determine if the view controller’s view is being hidden because the view controller was just dismissed.
0 0
原创粉丝点击