2 个纵向和横向故事板 [英] 2 storyboards for portrait and landscape

查看:32
本文介绍了2 个纵向和横向故事板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能的方法来创建两个故事板,一个纵向和一个横向,然后根据设备方向访问它们?类似:

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????

推荐答案

我相信有一种更简单的方法来处理不同的方向.

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

您可以使用 layoutSubviews 方法直接从视图内管理视图的布局.

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.

这确实假设您只想管理布局,如果您需要不同的故事板,因为导航因方向而异(Apple 不推荐),这对您没有帮助;但同样,这真的不是最好的方法.

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.

希望有帮助!

这篇关于2 个纵向和横向故事板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆