iPhoneX横竖屏旋转适配
2018-03-12 本文已影响69人
xxxxxxxxx_ios
横竖屏幕适配
- 在控制器中重写以下方法
其中self.viewTop
self.viewLeft
self.viewRight
self.viewBottom
分别为子UIView距离四边约束,旋转屏幕可以完全适配。
- (void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
UIEdgeInsets safeAreaInsets = UIEdgeInsetsZero;
if (@available(iOS 11.0, *)) {
safeAreaInsets = self.view.safeAreaInsets;
}
self.viewTop.constant = safeAreaInsets.top;
self.viewLeft.constant = safeAreaInsets.left;
self.viewRight.constant = safeAreaInsets.right;
self.viewBottom.constant = safeAreaInsets.bottom;
}