我试图用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)
}
}
Update 9/27/16 with correct answer
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .none
}