2 storyboards for portrait and landscape

≡放荡痞女 提交于 2019-12-10 19:55:35

问题


is there any possible way to create two storyboards, one portrait and one landscape, and then access them depending on the device orientation? something like:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    {
        self.storyboard = (one of the storyboards);
    }
    else
    {
        self.storyboard (the other);
    }
}

this code does not work. is there any code that will work????


回答1:


I believe there is a much easier way to deal with different orientations.

You can manage the view's layout directly from within the view using the layoutSubviews method.

This method is called every time the frame of the view is changed (for example when an orientation change happens).

Inside you can do the custom layout based on the view size.

This does assume that you want to manage only layout, if you need different storyboards because the navigation is different depending on orientation (which is not recommended by Apple) this will not help you; but again, it is really not the best way to do it.

Hope it helps!




回答2:


Changing storyboards on rotation is quite doable. It's almost the same as changing view controllers on rotation.

You should not shouldAutorotateToInterfaceOrientation:. This method is called to ask if rotation is allowed. It is not the rotation itself. You should use willRotateToInterfaceOrientation:duration: because this is called when rotation is about to begin.

As for changing view controllers in different story boards I'd suggest this video tutorial. I watched it a couple days ago and I found myself quite capable of using multiple storyboards after watching it.



来源:https://stackoverflow.com/questions/9590524/2-storyboards-for-portrait-and-landscape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!