如何以更小的尺寸呈现一个视图控制器[英] How to present a view controller with smaller size

本文是小编为大家收集整理的关于如何以更小的尺寸呈现一个视图控制器的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我希望显示的视图控制器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)
}

推荐答案

尝试这个..

@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
}

其他推荐答案

您可以简单地使用容器视图来显示较小的视图控制器.这是一个关于容器视图的绝佳教程: https://cococoacasts. com/manding-view-controllers-with-container-view-controllers/

希望这很有帮助:)

本文地址:https://www.itbaoku.cn/post/2091149.html

问题描述

I want presented view controller vc2 in smaller size than the screen, how to do that in Swift 3 ?? Thanks for help. This is my code:

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

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

推荐答案

Try this..

@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
}

其他推荐答案

You can simply use a container view to display the smaller view controller. Here is a great tutorial on container views: https://cocoacasts.com/managing-view-controllers-with-container-view-controllers/

Hope this was helpful :)