iPad上modalPresentationStyle-FormSheet的高度到底是多少? [英] What exactly is the height of modalPresentationStyle - FormSheet on iPad?
问题描述
在iPad上,modalPresentationStyle-FormSheet的高度到底是多少?我写了一行代码来获取self.view的高度,像这样:
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:
在ModalViewController上没有表单,高度为 1024.0
在FormPresentationStyle上使用表格,将高度设置为 1024.0 ,这是错误的,因为高度应该小于1024.0
With Formsheet on modalPresentationStyle, height at 1024.0 which is wrong because the height is supposed to be less than 1024.0
有什么主意吗?我需要使用formsheet从self.view.frame.size.height获得正确的高度,因为我需要在代码中的某个地方编写公式.我不需要更改表单的大小.
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.
推荐答案
不要在viewDidLoad
内而是在viewDidAppear
内实现println
.
Don't implement your println
inside viewDidLoad
but inside viewDidAppear
.
在情节提要中使用 Segue:模态呈现和演示文稿:表单工作表呈现的以下类在viewWillAppear
或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
}
}
这篇关于iPad上modalPresentationStyle-FormSheet的高度到底是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!