2017-08-02 77 views
0

我的目标是以编程方式提供一个UIViewController作为弹出窗口。如何在iOS Swift中以编程方式呈现弹出窗口?

enter image description here

正如你所看到的,过渡样式设置为Cross Dissolve和演示设置为Over current context。因此,从技术上讲,如果我点击按钮,过渡将起作用,我的目标是以编程方式进行。

func clickButton() { 
    //What should I do here? 


} 

如何以编程方式在clickButton上显示弹出窗口?如果您希望以编程方式关闭它

内PopupVC

self.dismiss(animated: true, completion: nil) 
+0

所以你在故事板中定义它,但想让它以编程方式查看?或者想要编码并推送它以编程方式查看? –

+0

尝试其中之一:https://github.com/IcaliaLabs/Presentrlog https://github.com/Orderella/PopupDia – YoCoh

回答

2

如果您呈现

+0

如何传递数据? – sinusGob

+0

它是'vc.profileImage'?如果我想在'PopViewController'本身传递一个函数的数据会怎么样 – sinusGob

0

你可以试试这个视图控制器m odally。你可以这样做。

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) 
    } 
} 
0

试试这个

let rateViewController = RatePopupVC() 
rateViewController.modalTransitionStyle = .crossDissolve 
rateViewController.modalPresentationStyle = .overCurrentContext 
self.present(rateViewController, animated: true, completion: nil) 

func clickButton() { 

    let vc : PopupVC = storyboard!.instantiateViewControllerWithIdentifier("PopupVCID") as! PopupVC 
    vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
    self.presentViewController(vc, animated: true, completion: nil) 
} 
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) 
相关问题