我尝试使用UIPopoverPresentationController
来显示一个不占据整个屏幕的popover
。我已经按照许多不同的教程进行了尝试,但仍然没有成功。
这是我的代码。它正确地实例化了ViewController
,但它占据了整个屏幕而不是像我在preferredContentSize
中定义的那样只占用较小的屏幕。
func showPopover() {
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("PopupTimePickerViewController") as PopupTimePickerViewController
vc.modalPresentationStyle = .Popover
vc.preferredContentSize = CGSizeMake(200, 100)
if let presentationController = vc.popoverPresentationController {
presentationController.delegate = self
presentationController.permittedArrowDirections = .Up
presentationController.sourceView = self.view
presentationController.sourceRect = CGRectMake(0, 0, 50, 50)
self.presentViewController(vc, animated: true, completion: nil)
}
}
已于2016年9月27日更新并提供正确答案
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .none
}
adaptivePresentationStyleForPresentationController
方法。 - gabbler