Swift 第二个vc比初始vc小

Swift 第二个vc比初始vc小,swift,ipad,uiviewcontroller,transition,updates,Swift,Ipad,Uiviewcontroller,Transition,Updates,昨天更新后,我在iPad上遇到了这个问题:如果我加载第二个视图控制器,它看起来比第一个更小(见下图)。有趣的是,自从我在iPad上更新了新的iOS后,这种情况才开始发生。iPhone上没有这样的问题:两个风投的大小都一样 代码如下: import UIKit class StartVC: UIViewController, ButtonDelegate { var width = CGFloat() var height = CGFloat() override fun

昨天更新后,我在iPad上遇到了这个问题:如果我加载第二个视图控制器,它看起来比第一个更小(见下图)。有趣的是,自从我在iPad上更新了新的iOS后,这种情况才开始发生。iPhone上没有这样的问题:两个风投的大小都一样

代码如下:

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!")

   }


}

自iOS 13发布以来,系统默认自动选择视图控制器的模式显示样式

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

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

希望这有帮助

将代码从
viewDidLoad
移动到
viewDidLayoutSubviews
,看看会发生什么。Mumtaz,我现在尝试了:结果相同。我相信您使用的是iOS 13?是的,iPadOS 13.1.2是的,这是个问题。非常感谢你。