iOS change auto layout constraints when device rotates

前端 未结 3 1524
温柔的废话
温柔的废话 2020-12-07 08:42

I want to modify the layout constraints when the device rotates. My UIViewController is composed of 2 UIViews, in landscape they are horizontally a

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 09:20

    override -(void) viewWillLayoutSubviews in your UIViewController to update your constraints as below code:

    -(void) viewWillLayoutSubviews {
         switch(self.interfaceorientation)
         {
              case UIInterfaceOrientationLandscapeLeft:
    
                  break;
              case UIInterfaceOrientationLandscapeRight:
    
                  break;
    
              case UIDeviceOrientationPortrait:
    
                  break;
    
              case UIDeviceOrientationPortraitUpsideDown:
    
                  break;
    
         }
    }
    

提交回复
热议问题