在ios中判断一个viewcontroller是否已经正常present

2017/5/24 posted in  iOS

之前present一个视图的时候,从来没有研究过如何判断一个视图是都已经正常弹出.比如下面这个方法是否正常执行:

[documentInteractionController presentPreviewAnimated:YES]

然而今天有一个需求需要知道上述方法是否正常执行,并弹出视图.

之后通过阅读该方法的api文档后发现:

// Bypasses the menu and opens the full screen preview window for the item at URL.  Returns NO if the item could not be previewed.
// Note that you must implement the delegate method documentInteractionControllerViewControllerForPreview: to preview the document.
- (BOOL)presentPreviewAnimated:(BOOL)animated;

该方法返回一个BOOL类型的值:当没有正常执行该方法时,会返回NO.正常返回YES.

类似的还有如下方法:

- (BOOL)isBeingPresented NS_AVAILABLE_IOS(5_0);
- (BOOL)isBeingDismissed NS_AVAILABLE_IOS(5_0);

- (BOOL)isMovingToParentViewController NS_AVAILABLE_IOS(5_0);
- (BOOL)isMovingFromParentViewController NS_AVAILABLE_IOS(5_0);

来判断viewController是消失还是出现在当前页面中.