Force popover on iPhone with programmatically created UIPopoverPresentationController

后端 未结 2 1684
误落风尘
误落风尘 2021-02-07 10:30

I need to create a new popover view as the anchor is not visible in Interface Builder during compile time.

According to this post, implementing the delegate method will

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-07 11:15

    let contentView  = 
    PLMainNavigationManager.sharedInstance.storyboard.instantiateViewControllerWithIdentifier("PLSearchVCID") as! PLSearchVC
            contentView.modalPresentationStyle = UIModalPresentationStyle.Popover
            contentView.preferredContentSize = CGSizeMake(400.0, 500.0)
            var _popoverPresentationController = contentView.popoverPresentationController!
            _popoverPresentationController.delegate = self
            _popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.Any
            _popoverPresentationController.sourceView = self.view
           _popoverPresentationController.sourceRect = CGRectMake(-30, -280, 320, 400)  
            PLMainNavigationManager.sharedInstance.navigationController?.presentViewController(contentView, animated: true, completion: nil)
    

提交回复
热议问题