我希望提供的视图控制器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 :(得分:4)
试试这个..
@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
}
答案 1 :(得分:0)
您只需使用容器视图即可显示较小的视图控制器。这是一个关于容器视图的精彩教程:https://cocoacasts.com/managing-view-controllers-with-container-view-controllers/
希望这有用:)