我正在尝试显示一个带有 UISlider
的 popOver
,以允许用户控制 的
.textSize
WKWebView
这是我的做法:
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
中,我刚刚添加了一个委托(delegate)来获取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
告诉演示 Controller 使用原始演示样式,在您的情况下将显示一个 popover
。
关于objective-c - 防止 UIPopover 在 iPhone 6 plus 上横向显示为 UIPageSheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30463137/