繁体   English   中英

如何在iOS 6中强制将方向设为纵向

[英]How to force Orientation as Portrait in iOS 6

我正在使用具有4个UINavigationControllers的UITabBarController。

在第四个ViewController中,我只想将其方向限制为纵向,我正在使用以下方法,但对我不起作用,请帮助我。

-(NSUInteger)supportedInterfaceOrientations
{
     return UIInterfaceOrientationMaskPortrait;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
     return UIInterfaceOrientationPortrait;
} 

现在我正在使用自定义的UITabBarController,如下所示...

CustomTabBarController.m

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}

在ViewControllerToBePorted.m中

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}

-(BOOL)shouldAutorotate{
return NO;

}

谢谢您的回复..

从开发人员站点

“当在根视图控制器上显示视图控制器时,系统行为发生两种变化。首先,在确定是否支持方向时,使用显示的视图控制器代替根视图控制器。第二,显示的视图控制器可以如果视图控制器全屏显示,则用户界面也将以首选方向显示。用户应该看到该方向不同于设备方向并旋转设备。首选方向是大多数通常在必须以新的方向呈现内容时使用。”

如果父视图具有允许的方向,则不能限制子视图的方向。

试想一下这个例子,您的标签栏处于横向,然后按仅限于纵向的视图,会发生什么?

就像我说的,孩子的取向必须是父母的取向

转到info.plist将其作为源代码打开,您将看到这样

<key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>

去掉

<string>UIInterfaceOrientationLandscapeLeft</string>
            <string>UIInterfaceOrientationLandscapeRight</string>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM