防止 UIPopover 在 iPhone 6 plus 横向显示为 UIPageSheet

Prevent a UIPopover from being presented as UIPageSheet on iPhone 6 plus in landscape

我正在尝试显示一个 popOver,里面有一个 UISlider,以允许用户控制 WKWebViewtextSize

这是我的做法:

MYCustomViewController *popoverContent = [[self storyboard] instantiateViewControllerWithIdentifier:@"MYCustomViewController"];
    popoverContent.delegate = self;
    popoverContent.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *popover = popoverContent.popoverPresentationController;
    popoverContent.preferredContentSize = CGSizeMake(220, 40);
    popover.delegate = self;
    popover.barButtonItem = (UIBarButtonItem *)sender;

    [self presentViewController:popoverContent animated:YES completion:nil];

在自定义 ViewController 中,我刚刚添加了一个委托来获取 UISlider

的值

我也实现了方法:

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
  return UIModalPresentationNone;
}

除 iPhone 6 Plus 横向(即紧凑高度)外,其他设备在所有设备上都运行良好,它将 popover 显示为 UIPageSheet

注意:我在 UISplitViewController

detailViewController 中显示 UIbarButtonItem 的弹出窗口

我按照@Joshua

的建议,通过实现 UIAdaptivePresentationControllerDelegate: 的新 adaptivePresentationStyleForPresentationController:traitCollection: 方法解决了这个问题
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
    // This method is called in iOS 8.3 or later regardless of trait collection, in which case use the original presentation style (UIModalPresentationNone signals no adaptation)
    return UIModalPresentationNone;
}

UIModalPresentationNone 告诉呈现控制器使用原始呈现样式,在您的情况下将显示 popover.