我正在使用iOS 8的新自适应“以弹出形式呈现”功能。在StoryBoard中,我连接了一个简单的segue以进行呈现。它在iPhone 6 Plus上作为弹出视图展示得很好,在iPhone 4s上则显示为全屏视图(sheet style)。
问题在于,当以全屏视图显示时,我需要向视图添加一个“完成”按钮,以便可以调用dismissViewControllerAnimated。而当它显示为弹出视图时,我不想显示“完成”按钮。
我尝试查看presentationController和popoverPresentationController的属性,但是找不到任何告诉我它是否实际上被显示为弹出视图的内容。
NSLog( @"View loaded %lx", (long)self.presentationController.adaptivePresentationStyle ); // UIModalPresentationFullScreen
NSLog( @"View loaded %lx", (long)self.presentationController.presentationStyle ); // UIModalPresentationPopover
NSLog( @"View loaded %lx", (long)self.popoverPresentationController.adaptivePresentationStyle ); // UIModalPresentationFullScreen
NSLog( @"View loaded %lx", (long)self.popoverPresentationController.presentationStyle ); // UIModalPresentationPopover
adaptivePresentationStyle始终返回UIModalPresentationFullScreen,而presentationStyle始终返回UIModalPresentationPopover。
查看UITraitCollection时,我确实发现了一个名为"_UITraitNameInteractionModel"的特性,只有在以Popover形式显示时才设置为1。然而,Apple不通过popoverPresentationController的traitCollection直接提供对该特性的访问。