PopoverViewController方法
let vc = SFSafariViewController(url: URL, entersReaderIfAvailable:false)
vc.modalPresentationStyle = .popover
vc.preferredContentSize = CGSize(width: self.view.frame.width/2, height: self.view.frame.height/2) // Or put any size
if let popover = vc.popoverPresentationController {
popover.sourceView = self.view // You can also put the source button
popover.permittedArrowDirections = .any
popover.sourceRect = CGRect(x: 0, y: 0, width: 85, height: 30)
popover.delegate = self
self.present(vc, animated: true, completion: nil)
}
然後宣佈這個子類:
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate
但是這只是針對iPad方面的工作,所以把這個:
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
Result