2017-06-20 62 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

我添加一個方法:func presentationController(forPresented呈現:UIViewController,呈現:UIViewController?,來源:UIViewController) - > UIPresentationController? { 返回SmallViewController(presentedViewController:呈現,呈現:呈現) } 和一個類:類SmallViewController:UIPresentationController { 倍率VAR frameOfPresentedViewInContainerView:{的CGRect返回 的CGRect(X:0,Y:200,寬度:containerView .bounds .width,containerView:.bounds.height/2) } } 但是效果不好。 V2是一個表格,它會滾動很慢。 – Peterq2001

相關問題