1.当前的UIViewController需要实现 UIPopoverPresentationControllerDelegate
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
2.弹出视图
if let pop = storyboard?.instantiateViewController(withIdentifier: "show_popover"),let btn = sender as? UIButton {
pop.modalPresentationStyle = .popover
pop.popoverPresentationController?.delegate = self
pop.popoverPresentationController?.sourceView = btn
pop.popoverPresentationController?.sourceRect = btn.bounds
pop.preferredContentSize = CGSize(width: 200, height: 100)
pop.popoverPresentationController?.permittedArrowDirections = .up
present(pop, animated: true, completion: nil)
}
网友评论