UIPopoverPresentationController on iPhone with iOS 10

前端 未结 4 621
刺人心
刺人心 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:29

    You are connecting delegate after presenting view. How it will return .none from delegate and show as popover. Use this :-

        func clicked(_ sender: Any) {
    
            let vc = UIViewController()
            vc.view.backgroundColor = UIColor.blue
            vc.modalPresentationStyle = .popover
    
            vc.preferredContentSize = CGSize(width: 200, height: 200)
    
            let ppc = vc.popoverPresentationController
            ppc?.permittedArrowDirections = .any
            ppc?.delegate = self
            ppc?.barButtonItem = navigationItem.rightBarButtonItem
            ppc?.sourceView = sender
    
            present(vc, animated: true, completion: nil)
    
        }
    

提交回复
热议问题