即使对于iPad sim,也调用了adaptivePresentationStyleForPresentationController

时间:2015-06-22 17:54:24

标签: ios8 adaptive-ui

我有一个viewcontroller实现UIPopoverPresentationControllerDelegate方法:

adaptivePresentationStyleForPresentationController(controller: UIPresentationController!, traitCollection: UITraitCollection!) -> UIModalPresentationStyle 

据我所知,这应该仅适用于iPhone 6这样的小巧尺寸,而不适用于iPad。但是在一个项目中,它甚至被称为iPad,因此,我不会得到一个popover但是全屏模式的东西。

我无法看到可能导致这种情况发生的原因。我查看了另一个具有大致相同设置的项目,并确认在iPad sim(仅限iphone)期间不会调用此方法。

其他人有这种经历吗?

2 个答案:

答案 0 :(得分:2)

我发现了什么是错的。我在代码完成期间选择了错误的func,我打算使用的正确委托方法是:

adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle

不是

adaptivePresentationStyleForPresentationController(controller: UIPresentationController!, traitCollection: UITraitCollection!) -> UIModalPresentationStyle 

答案 1 :(得分:0)

根据您的iOS级别,您应该使用adaptivePresentationStyleForPresentationController: traitCollection:

我使用这种方法(返回.None)并且它已经在我迄今为止测试的所有设备上工作。

adaptivePresentationStyleForPresentationController:的Apple文档中,它说:

  

在iOS 8.3及更高版本中,使用adaptivePresentationStyleForPresentationController:traitCollection:方法来处理所有特征更改而不是此方法。如果未实现该方法,则可以在转换为水平紧凑环境时使用此方法更改演示文稿样式。

修改 对于我的目标iOS 8,我实际上使用了这两种方法。 8.3之前的人不会使用traitCollection:

的那个