问题
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