gpt4 book ai didi

swift - 第二个 vc 小于初始 vc

转载 作者:行者123 更新时间:2023-11-30 10:34:57 30 4
gpt4 key购买 nike

昨天更新后,我在 iPad 上遇到了这个问题:如果我加载第二个 View Controller ,它看起来比第一个 View Controller 小(见下图)。有趣的是,自从我在 iPad 上更新了新的 iOS 后,这种情况才发生。 iPhone 上不存在这样的问题:两个 VC 的大小相同。

这是代码:

import UIKit

class StartVC: UIViewController, ButtonDelegate {


var width = CGFloat()
var height = CGFloat()




override func viewDidLoad() {
super.viewDidLoad()

width = view.frame.width
height = view.frame.height

setTestBtn()


view.backgroundColor = UIColor.purple

}

func setTestBtn(){

let a = Button(frame: CGRect(x: 0,y: 0, width: width*0.2, height: width*0.2))
a.center = CGPoint(x: width*0.5, y: height*0.5)
a.backgroundColor = .cyan
a.delegate = self
a.setLabel()
a.label.text = "Go to the MainVC"
view.addSubview(a)
}

func buttonClicked(sender: Button) {

let vc = self.storyboard?.instantiateViewController(withIdentifier: "mainVC") as! MainVC
let transition = CATransition()
transition.duration = 2
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
view.window!.layer.add(transition, forKey: kCATransition)

vc.view.frame = view.bounds

self.present(vc, animated: true, completion: nil)


print("# ViewController func buttonClicked() OK!")

}




import UIKit

class MainVC: UIViewController, ButtonDelegate {

var width = CGFloat()
var height = CGFloat()

override func viewDidLoad() {
super.viewDidLoad()

width = view.frame.width
height = view.frame.height

setTestBtn()

view.backgroundColor = .red


}

func setTestBtn(){

let a = Button(frame: CGRect(x: 0,y: 0, width: width*0.2, height: width*0.2))
a.center = CGPoint(x: width*0.5, y: height*0.5)
a.backgroundColor = .orange
a.delegate = self
a.setLabel()
a.label.text = "Go to the StartVC"
view.addSubview(a)
}

func buttonClicked(sender: Button) {

let vc = self.storyboard?.instantiateViewController(withIdentifier: "startVC") as! StartVC
let transition = CATransition()
transition.duration = 2
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
view.window!.layer.add(transition, forKey: kCATransition)

vc.view.frame = view.bounds

self.present(vc, animated: true, completion: nil)

print("# ViewController func buttonClicked() OK!")

}


}

Initial View Controller iPad Second View Controller iPad Initial View Controller iPhone Second View Controller iPhone

最佳答案

自 iOS 13 发布以来,View Controller 的模态呈现样式默认由系统自动选择。

如果您想抵消这种影响,这可以帮助您。

vc.modalPresentationStyle = .overFullScreen
self.present(vc, animated: true, completion: nil)

希望这有帮助!

关于swift - 第二个 vc 小于初始 vc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58235033/

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