iPhoneX横竖屏旋转适配

横竖屏幕适配

  • 在控制器中重写以下方法
    其中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;
}

你可能感兴趣的:(iPhoneX横竖屏旋转适配)