2017-08-02 6 views
0

私の目標は、UIViewControllerをプログラムでポップオーバーとして提示することです。IOS Swiftでプログラムでポップオーバーを表示するにはどうすればよいですか?

enter image description here

あなたが見ることができるように、トランジションスタイルがCross Dissolveに設定され、プレゼンテーションがOver current contextに設定されています。技術的には、ボタンをクリックすると、移行が機能し、私の目標はプログラム的に行うことです。

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


} 

clickButtonにプログラムでポップオーバーを表示するにはどうすればよいですか?

+0

あなたはストーリーボードで定義しましたが、プログラムで表示できるようにしたいと考えていますか?それをコード化し、それをプログラム的に見るために押したいと思っていますか? –

+0

これらのいずれかを試してみてください:https://github.com/IcaliaLabs/Presentrlog https://github.com/Orderella/PopupDia – YoCoh

答えて

2

は、あなたが提示されている場合ビューコントローラmオードリー。あなたはこのようにすることができます。

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

どのようにデータを渡すのですか? – sinusGob

+0

は 'vc.profileImage'ですか? 'PopViewController'自体の関数にデータを渡したいのであれば – sinusGob

0

あなたはこれを試すことができます。

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

をあなたはこの試しプログラムで

インサイドPopupVC

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

それを閉じたい場合は:

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) 
関連する問題