UIPopoverPresentationController on iPhone doesn't produce popover

后端 未结 4 1515
孤独总比滥情好
孤独总比滥情好 2020-11-27 15:37

I\'m trying to implement the new UIPopoverPresentationController in my iPhone app (using Objective C). What I want is a simple popover with a tableview that ema

4条回答
  •  孤城傲影
    2020-11-27 16:21

    SWIFT 3.X

    This will show the popover at the center of the screen

    class CommonViewController: UIViewController, UIPopoverPresentationControllerDelegate{
    
        func adaptivePresentationStyle(
            for controller: UIPresentationController,
            traitCollection: UITraitCollection)
            -> UIModalPresentationStyle {
                return .none
        }
    
        func showPopover() {
            let myViewController = UIViewController()
            myViewController.preferredContentSize = CGSize(width: 320, height: 200)
            myViewController.modalPresentationStyle = .popover
    
            let popOver = myViewController.popoverPresentationController
            popOver?.delegate = self
    
            self.present(myViewController, animated: true, completion: nil)
            popOver?.permittedArrowDirections = .up
            popOver?.sourceView = self.view
    
            let rect = CGRect(
                origin: CGPoint(x: self.view.frame.width/2,
                                y: self.view.frame.height/2),
                size: CGSize(width: 1, height: 1)
            )
            popOver?.sourceRect = rect
        }
    }
    

提交回复
热议问题