What exactly is the height of modalPresentationStyle - FormSheet on iPad?

不打扰是莪最后的温柔 提交于 2019-12-24 02:22:37

问题


What exactly is the height of modalPresentationStyle - FormSheet on iPad? I wrote a line of code to get the height of self.view like this:

println("Height - modalPresentationStyle FormSheet: \(self.view.frame.size.height)")

I got these two results after testing:

Without Formsheet on ModalViewController, height at 1024.0

With Formsheet on modalPresentationStyle, height at 1024.0 which is wrong because the height is supposed to be less than 1024.0

Any idea what is wrong with it? I need to get the right height from self.view.frame.size.height with formsheet because I need to write the formula somewhere in the code. I don't need to change the size of formsheet.


回答1:


Don't implement your println inside viewDidLoad but inside viewDidAppear.

The following class that is presented in the Storyboard with Segue: Present Modally and Presentation: Form Sheet gives different results for the same println when called in viewDidLoad, viewWillAppear or viewDidAppear:

class ViewController2: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        println(view.frame) // (0.0, 0.0, 768.0, 1024.0)
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        println(view.frame) // (0.0, 0.0, 768.0, 1024.0)
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        println(view.frame) // (0.0, 0.0, 540.0, 620.0) // Correct values
    }

}


来源:https://stackoverflow.com/questions/30491951/what-exactly-is-the-height-of-modalpresentationstyle-formsheet-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!