gpt4 book ai didi

ios - 如何在 iOS 中一键更改 UIViewController?

转载 作者:行者123 更新时间:2023-11-30 13:55:56 24 4
gpt4 key购买 nike

我将其放入我的 ViewController1 类中,但代码返回了错误:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
let vc: ViewController2 = ViewController2(nibName: "ViewController2", bundle: nil)
self.presentViewController(vc, animated: true, completion: nil)
}

我的代码有什么问题吗?

最佳答案

由于您的 Storyboard 上没有第二个 UIViewController,因此请实例化一个并呈现它。我已将 secondViewControllerbackgroundColor 更改为红色,这样您就可以实际看到 View 之间的过渡。

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)

let secondViewController = UIViewController()
secondViewController.view.layer.backgroundColor = UIColor.redColor().CGColor
self.presentViewController(secondViewController, animated: true, completion: nil)
}

关于ios - 如何在 iOS 中一键更改 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33616399/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com