版本:swift3.0
@IBAction func buttonOnClick(_ sender: UIButton) {
//要弹出的视图控制器
let viewCtrl = UIViewController()
//弹出视图大小
viewCtrl.preferredContentSize = CGSize(width: 250, height: 250)
viewCtrl.modalPresentationStyle = .popover
let popover = viewCtrl.popoverPresentationController
//弹出视图的位置
popover?.sourceRect = sender.frame
//代理:UIPopoverPresentationControllerDelegate
popover?.delegate = self
//弹出页面是相对于谁
popover?.sourceView = self.view
//箭头的指向
popover?.permittedArrowDirections = .up
//如果是tabBarItem弹出,则应该这样设置:
//popover.barButtonItem = sender
present(viewCtrl, animated: true, completion: nil)
}
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.none
}