【问题标题】:What exactly is the height of modalPresentationStyle - FormSheet on iPad?iPad 上 modalPresentationStyle - FormSheet 的高度到底是多少?
【发布时间】:2015-05-28 05:15:17
【问题描述】:

modalPresentationStyle - FormSheet 在 iPad 上的高度到底是多少?我写了一行代码来获取 self.view 的高度,如下所示:

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

我测试后得到了这两个结果:

ModalViewController 上没有 Formsheet,高度为 1024.0

在 modalPresentationStyle 上使用 Formsheet,高度在 1024.0 这是错误的,因为高度应该小于 1024.0

知道它有什么问题吗?我需要使用表单从 self.view.frame.size.height 获得正确的高度,因为我需要在代码中的某处编写公式。我不需要更改表单的大小。

【问题讨论】:

    标签: ios swift modalviewcontroller


    【解决方案1】:

    不要在viewDidLoad 内部实现您的println,而是在viewDidAppear 内部实现。

    在情节提要中显示的以下类与 Segue: Present ModallyPresentation: Form Sheet 在 @987654325 中调用相同的 println 时会给出不同的结果@、viewWillAppearviewDidAppear

    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
        }
    
    }
    

    【讨论】:

    • 哇,非常感谢。我什至没有想过在 viewDidAppear 内部实现我的 println 。现在它工作得很好。再次感谢!
    • 你很棒。谢谢。
    猜你喜欢
    • 2011-08-10
    • 2011-05-11
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-01
    • 2010-10-10
    相关资源
    最近更新 更多