我的目标是以编程方式将UIViewController呈现为一个popover。
如您所见,转换样式设置为Cross Dissolve
,演示文稿设置为Over current context
。所以从技术上讲,如果我点击按钮,过渡将起作用,我的目标是以编程方式进行。
func clickButton() {
//What should I do here?
}
如何在clickButton
上以编程方式显示popover?
答案 0 :(得分:4)
如果您以模态方式呈现视图控制器。你可以这样做。
func clickButton() {
if let vc = self.storyboard?.instantiateViewController(withIdentifier:"YOUR_VIEW_CONTROLLER_ID") {
vc.modalTransitionStyle = .crossDissolve;
vc.modalPresentationStyle = .overCurrentContext
self.present(vc, animated: true, completion: nil)
}
}
答案 1 :(得分:0)
你可以试试这个:
let rateViewController = RatePopupVC()
rateViewController.modalTransitionStyle = .crossDissolve
rateViewController.modalPresentationStyle = .overCurrentContext
self.present(rateViewController, animated: true, completion: nil)
如果要以编程方式关闭它
PopupVC内部
self.dismiss(animated: true, completion: nil)
答案 2 :(得分:0)
试试这个:
func clickButton() {
let vc : PopupVC = storyboard!.instantiateViewControllerWithIdentifier("PopupVCID") as! PopupVC
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.presentViewController(vc, animated: true, completion: nil)
}
答案 3 :(得分:0)
请尝试以下代码。
let popupview = storyboard?.instantiateViewController(withIdentifier: "YourViewController")
popupview.view.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
self.addChildViewController(popupview)
self.view.addSubview(popupview.view)
popupview.didMove(toParentViewController: popupview)