守着一只汪
早些时候在IOS 7.0-11.0中<弃用> UIKit使用TopLayoutGuide & 底层指南那就是UIView财产iOS 11+用途安全AreaLayoutGuide这也是UIView财产使能安全区布局指南来自文件检查器的复选框。安全区域可以帮助您将视图放置在整个界面的可见部分中。在……里面视频流安全区域还包括屏幕的过扫描接口,表示屏幕边框覆盖的区域。SecurityAreaLayoutGuide反映视图中未被导航条、选项卡条、工具栏和其他祖先视图覆盖的部分。使用安全区域作为布局您的内容的帮助,如UIButton等。在为iPhoneX设计时,您必须确保布局填充屏幕,并且不会被设备的圆角、传感器外壳或访问主屏幕的指示器所掩盖。确保背景延伸到显示的边缘,垂直滚动布局,如表和集合,一直延续到底部。iPhoneX上的状态栏比其他iPhone高。如果应用程序采用固定的状态栏高度来定位状态栏以下的内容,则必须更新应用程序,以便根据用户的设备动态定位内容。请注意,当语音记录和位置跟踪等后台任务处于活动状态时,iPhoneX上的状态栏不会更改高度print(UIApplication.shared.statusBarFrame.height)//44 for iPhone X, 20 for other iPhones家用指示器容器高度为34点。一旦你启用安全区布局指南您可以看到接口生成器中列出的安全区域约束属性。可以设置相应的约束。self.view.safeAreaLayoutGuide作为-objc: self.demoView.translatesAutoresizingMaskIntoConstraints = NO;
UILayoutGuide * guide = self.view.safeAreaLayoutGuide;
[self.demoView.leadingAnchor constraintEqualToAnchor:guide.leadingAnchor].active = YES;
[self.demoView.trailingAnchor constraintEqualToAnchor:guide.trailingAnchor].active = YES;
[self.demoView.topAnchor constraintEqualToAnchor:guide.topAnchor].active = YES;
[self.demoView.bottomAnchor constraintEqualToAnchor:guide.bottomAnchor].active = YES;斯威夫特 demoView.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
let guide = self.view.safeAreaLayoutGuide
demoView.trailingAnchor.constraint(equalTo: guide.trailingAnchor).isActive = true
demoView.leadingAnchor.constraint(equalTo: guide.leadingAnchor).isActive = true
demoView.bottomAnchor.constraint(equalTo: guide.bottomAnchor).isActive = true
demoView.topAnchor.constraint(equalTo: guide.topAnchor).isActive = true
} else {
NSLayoutConstraint(item: demoView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier:
1.0, constant: 0).isActive = true
NSLayoutConstraint(item: demoView, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier:
1.0, constant: 0).isActive = true
NSLayoutConstraint(item: demoView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier:
1.0, constant: 0).isActive = true
NSLayoutConstraint(item: demoView, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier:
1.0, constant: 0).isActive = true
}