search

Home  >  Q&A  >  body text

xcode - iOS开发xib中横竖屏两种不同布局,使用autoLayout添加的约束无法正常使用?

xib中针对横竖屏做了两个view,横竖屏切换着使用。添加约束的时候,应该怎么添加?已经试过相对四周均为0了,但是横竖屏一切换,显示就出现一些问题。

伊谢尔伦伊谢尔伦2771 days ago2087

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-18 09:39:53

    Sorry, I checked the code again. It was the view association error in my own code. There is no problem with autoLayout. Attached is my approach:

    How to rotate the screen:
    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {

    // Executed when the screen changes from portrait to landscape

        self.view = _hView;
    }else{

    // Executed when the screen changes from landscape to portrait

        self.view = _vView;
    }

    }

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:39:53

    Look at the size class.
    Different constraints can be set for different size categories

    reply
    0
  • Cancelreply