UIPopoverPresentationController on iPhone with iOS 10

前端 未结 4 623
刺人心
刺人心 2021-01-14 09:05

I\'m trying to display a ViewController as a popover on an iPhone. I have already been through several answers on SO and the rest of the web but none have worked so far. I w

4条回答
  •  暖寄归人
    2021-01-14 09:35

    import UIKit
    class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
    
    override func viewDidLoad() {
            super.viewDidLoad()
            navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(clicked(_:)))
        }
    
    
    
    func clicked(_ sender: Any) {
            let vc = UIViewController()
            vc.view.backgroundColor = UIColor.blue
            vc.preferredContentSize = CGSize(width: 200, height: 200)
            vc.modalPresentationStyle = .popover
            let ppc = vc.popoverPresentationController
            ppc?.permittedArrowDirections = .any
            ppc?.delegate = self
            ppc!.sourceView = sender as? UIView 
            ppc?.barButtonItem = navigationItem.rightBarButtonItem
            present(vc, animated: true, completion: nil)
        }
    
     func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
            return .none
        }
    
    
    }
    

提交回复
热议问题