【发布时间】:2017-08-10 06:32:23
【问题描述】:
我想用preferredContentSize(W: 250, H: 50)在中心显示PopoverViewController,但是它显示的是那个ViewController的全尺寸,请找到我做错的地方并纠正它。
class ViewController: UIViewController,
UIPopoverControllerDelegate, UIPopoverPresentationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func PopBtn_Action(_ sender: Any) {
let popController = self.storyboard!.instantiateViewController(withIdentifier: "PincodeViewController") as! PincodeViewController
// set the presentation style
popController.modalPresentationStyle = UIModalPresentationStyle.popover
// set up the popover presentation controller
popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up
popController.popoverPresentationController?.delegate = self
popController.popoverPresentationController?.sourceView = sender as? UIView // button
popController.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.width/2, y: self.view.bounds.height/2, width: 1, height: 1)
popController.preferredContentSize = CGSize(width: 250, height: 250)
// present the popover
self.present(popController, animated: true, completion: nil)
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
func popoverPresentationControllerShouldDismissPopover(popoverPresentationController: UIPopoverPresentationController) -> Bool {
return true
}
func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
}
【问题讨论】:
-
你检查过
popController.popoverPresentationController?不是nil吗?
标签: ios swift3 uipopovercontroller popover