iOS 8 iPhone上的UIPopoverPresentationController

有谁知道是否UIPopoverPresentationController可以在iPhone上显示弹出窗口?想知道苹果是否在iOS 8上添加了此功能,以试图为iPad和iPhone创建更统一的演示控制器。


不确定是否可以从Beta提问/回答问题。在这种情况下,我将其删除。


幕布斯6054654
浏览 868回答 3
3回答

慕容708150

您可以UIModalPresentationFullScreen使用adaptivePresentationStyleForPresentationController:通过提供的方法来覆盖默认的自适应行为(在紧凑的水平环境中,即iPhone)&nbsp; UIPopoverPresentationController.delegate。UIPresentationController使用此方法询问要使用的新演示文稿样式,在您的情况下,简单地返回UIModalPresentationNone将导致UIPopoverPresentationController呈现为弹出窗口而不是全屏。这是一个使用情节提要中的segue设置的弹出窗口示例,从UIBarButtonItem到“ 模态呈现 ”UIViewControllerclass SomeViewController: UIViewController, UIPopoverPresentationControllerDelegate {&nbsp; &nbsp; // override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { // swift < 3.0&nbsp; &nbsp; override func prepare(for segue: UIStoryboardSegue, sender: Any?) {&nbsp; &nbsp; &nbsp; &nbsp; if segue.identifier == "PopoverSegue" {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if let controller = segue.destinationViewController as? UIViewController {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; controller.popoverPresentationController.delegate = self&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; controller.preferredContentSize = CGSize(width: 320, height: 186)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; // MARK: UIPopoverPresentationControllerDelegate&nbsp; &nbsp; //func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!) -> UIModalPresentationStyle { // swift < 3.0&nbsp; &nbsp; func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {&nbsp; &nbsp; &nbsp; &nbsp; // Return no adaptive presentation style, use default presentation behaviour&nbsp; &nbsp; &nbsp; &nbsp; return .None&nbsp; &nbsp; }}WWDC 2014会议214“ iOS8中的View Controller Advancement”中提到了此技巧(36:30)

largeQ

我找到了一些解决方法。在Xcode6.1上,使用presentationController.delegate代替popoverPresentationController.delegate。- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{&nbsp; &nbsp; if ([segue.identifier compare:@"showPopOver"] == NSOrderedSame) {&nbsp; &nbsp; &nbsp; &nbsp; UINavigationController * nvc = segue.destinationViewController;&nbsp; &nbsp; &nbsp; &nbsp; UIPresentationController * pc = nvc.presentationController;&nbsp; &nbsp; &nbsp; &nbsp; pc.delegate = self;&nbsp; &nbsp; }}#pragma mark == UIPopoverPresentationControllerDelegate ==- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{&nbsp; &nbsp; return UIModalPresentationNone;}在WWDC 2014“ iOS8中的View Controller Advances”中,以下代码可以显示iPhone上的弹出窗口。- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{&nbsp; &nbsp; UINavigationController * nvc = segue.destinationViewController;&nbsp; &nbsp; UIPopoverPresentationController * pvc = nvc.popoverPresentationController;&nbsp; &nbsp; pvc.delegate = self;}#pragma mark == UIPopoverPresentationControllerDelegate ==- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{&nbsp; &nbsp; return UIModalPresentationNone;}但是在Xcode 6.1上,这些代码显示了FullScreen演示...(nvc.popoverPresentationController为nil)我怀疑这可能是苹果的错误。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

iOS