2017-06-20 8 views
1

ビューコントローラvc2を画面よりも小さいサイズで表示したいのですが、Swift 3ではどのように行うのですか?手伝ってくれてありがとう。 これは私のコードです:小さいサイズのビューコントローラを表示するには

@IBAction func leftButtonPressed(_ sender: UIButton) { 
    let vc2 = self.storyboard?.instantiateViewController(withIdentifier: "Controller2") as! ViewController2 
    vc2.modalPresentationStyle = .currentContext 

    present(vc2, animated: true, completion: nil) 
} 
+0

あなたはそれが現在のコンテキストをオーバーレイし、ことができますので、スペース上左がクリッカブルになりたいです下のものをクリックしますか? 視覚的に小さくしたいだけですが、やはり対話の面で画面全体を取るべきですか? –

+0

私は視覚的に小さく、インタラクションの面で画面全体を取りたいと思っています。親画面の上部が見えます。 – Peterq2001

答えて

3

これを試してみてください。..

@IBAction func leftButtonPressed(_ sender: UIButton) { 
    let vc2 = self.storyboard?.instantiateViewController(withIdentifier: "Controller2") as! ViewController 
    vc2.providesPresentationContextTransitionStyle = true 
    vc2.definesPresentationContext = true 
    vc2.modalPresentationStyle=UIModalPresentationStyle.overCurrentContext 
    self.present(vc2, animated: true, completion: nil) 

    // Make sure your vc2 background color is transparent 
    vc2.view.backgroundColor = UIColor.clear 
} 
+0

これは、非常にありがとう、動作します。私はまた、UIViewControllerTransitioningDelegateメソッドを追加しようとしています: – Peterq2001

+0

あなたを歓迎.. :) – Bilal

+0

私はメソッドを追加します:(UIViewController、プレゼンテーション: { リターンSmallViewController(presentedViewController:提示し、提示:提示) } クラス:クラスSmallViewController:UIPresentationController { オーバーライドするvar frameOfPresentedViewInContainerView:CGRect { リターンCGRect(X:0、Y:200、幅:containerView .bounds .width、height:containerView!.bounds.height/2) } } ただし、うまく機能しません。 V2はテーブルであり、非常にゆっくりとスクロールします。 – Peterq2001

関連する問題