代码切换横竖屏

// 布局子视图:当屏幕旋转的时候,可以重新布局子视图的位置
- (void)layoutSubviews {
    
    // 如果是竖屏,保持原来的尺寸
    
    if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) {
        
        self.button.frame = CGRectMake(50, CGRectGetMaxY(self.userTextField.frame) + 20, CGRectGetWidth(self.frame) - 100, 50);
        
    } else { // 否则横屏改变位置
        
        self.button.frame = CGRectMake(50, CGRectGetMaxY(self.userLabel.frame) + 20, 636, 50);
        
    }
    

  

原文地址:https://www.cnblogs.com/mingjieLove00/p/5537065.html