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

相关问题