如何知道视图控制器是否将呈现为弹出框或模态框?

Mar*_*kus 6 iphone uikit popover ipad ios

在呈现视图控制器之前,我将modalPresentationStyle属性设置为UIModalPresentationPopover。当在具有常规水平尺寸类别(横向的 iPad 和 iPhone 6+)的设备上运行时,这会将视图控制器呈现为弹出窗口,并在其他设备上呈现为模式/全屏。还可以通过覆盖来覆盖此行为adaptivePresentationStyleForPresentationController,以便视图控制器在所有设备上显示为弹出窗口。

我想知道在呈现视图控制器之后是否有可能知道它是否作为弹出框呈现?仅查看尺寸类是不行的,因为视图控制器可能会覆盖adaptivePresentationStyleForPresentationController.

明显的答案是,作为程序员,我应该知道我是否重写adaptivePresentationStyleForPresentationController,但我想编写一个函数,可以通过传入视图控制器或(或UIPopoverPresentationController任何其他对象)在运行时为任何视图控制器确定这一点需要)作为参数。

下面是一些展示视图控制器的代码:

navigationController = (UINavigationController *)[MVSStore sharedInstance].addViewController;
navigationController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:navigationController animated:YES completion:^{}];

UIPopoverPresentationController *popoverController = navigationController.popoverPresentationController;
popoverController.sourceView = self.view;
popoverController.sourceRect = CGRectMake(20, 20, 20, 20); // Just a dummy
popoverController.permittedArrowDirections = UIPopoverArrowDirectionAny;
Run Code Online (Sandbox Code Playgroud)

这是当前的代码,用于检测视图控制器是否显示为弹出窗口。但如上所述,它只是查看尺寸类别,并不适用于所有情况。

+ (BOOL)willPresentTruePopover:(id<UITraitEnvironment>)vc {
    return ([vc traitCollection].horizontalSizeClass == UIUserInterfaceSizeClassRegular);
}
Run Code Online (Sandbox Code Playgroud)

UIViewController我无法在或(或其他任何地方)中找到任何UIPopoverPresentationController可以立即为我提供此信息的属性或函数,但也许我遗漏了一些东西?

Dou*_*ill 2

使用UIAdaptivePresentationControllerDelegate方法presentationController:willPresentWithAdaptiveStyle:transitionCoordinator:。要在其他时间查询呈现样式,请向呈现控制器询问其adaptivePresentationStyleForTraitCollection:,并传递当前特征。这些方法是在 iOS\xc2\xa08.3 中添加的,尚未记录

\n