2017-10-19 187 views

回答

55

试试这个:

目标C

if (@available(iOS 11.0, *)) { 
    UIWindow *window = UIApplication.sharedApplication.keyWindow; 
    CGFloat topPadding = window.safeAreaInsets.top; 
    CGFloat bottomPadding = window.safeAreaInsets.bottom; 
} 

斯威夫特

if #available(iOS 11.0, *) { 
    let window = UIApplication.shared.keyWindow 
    let topPadding = window?.safeAreaInsets.top 
    let bottomPadding = window?.safeAreaInsets.bottom 
} 
14

要得到高度的布局指导你只是做

let guide = view.safeAreaLayoutGuide 
let height = guide.layoutFrame.size.height 

所以full frame height = 812.0safe area height = 734.0

下面就是绿色视图具有的guide.layoutFrame

帧的例子

enter image description here

+0

我更新了答案 – Ladislav

+0

感谢那是铅,我还想着。我不认为有更可靠的解决方案。但有了这个,我只能得到完全不安全的高度,对吧?每个区域的高度不是两个? – Tulleb

+0

一旦意见被列出来,这将给你正确的答案 – Ladislav

相关问题