强制iOS设备更改方向 [英] Force the iOS device to change orientation

查看:218
本文介绍了强制iOS设备更改方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,对于再次在这个论坛中多次提出的相同问题,我深表歉意.但是,我的问题是我尝试了所有建议的解决方案,但仍然没有解决我的问题的方法.

First of all, I would like to apologize for asking the same question again which has been asked in this forum many times. But, my problem is that I've tried all the suggested solutions but still I haven't got a solution to my problem.

我在Potrait模式下有一个ViewControllerA,在风景模式下有一个ViewControllerB.当设备从potrait变为风景时,我可以看到ViewControllerB在风景模式下打开,但是当设备旋转回到potrait模式时,会显示ViewControllerA,但仍处于风景模式.有人可以帮助我了解如何将其显示为potrait模式吗?

I have a ViewControllerA in Potrait mode and ViewControllerB in landscape mode. When the device changes from potrait to landscape, i can see ViewControllerB opening in landscape mode, but when the device is rotated back to potrait mode, ViewControllerA is displayed but still in landscape mode. Could anybody help me understand how can I display it back in potrait mode?

我尝试了以下操作,但对我没有帮助:

I have tried following things but nothing worked for me:

viewWillAppearViewControllerA中添加了以下代码:

Added following code in ViewControllerA in viewWillAppear:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

在此视图控制器中还添加了以下功能:

Have also added following functions in this view controller:

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
     return UIInterfaceOrientationPortrait;
}

推荐答案

希望通过使用supportedInterfaceOrientationsForWindow

Hope this helps you by using supportedInterfaceOrientationsForWindow

Appdelegate.h

@property () BOOL restrictRotation;

Appdelegate.m

  -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    //restrictRotation is BOOL value
     if(self.restrictRotation)//set the bool value to view controller which you want to load in landscape
          return UIInterfaceOrientationMaskLandscape;
     else
       return UIInterfaceOrientationMaskAll;
}

//在需要的地方拨打此电话

requiredViewController.m

-(void) restrictRotation:(BOOL) restriction
{

  appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
  appDelegate.restrictRotation = restriction;
}

//在ViewdidLoad()

//In ViewdidLoad()

- (void)viewDidLoad
 {
   [super viewDidLoad];
   [self restrictRotation:YES];//Set YES if required in Landscape mode
 }

这篇关于强制iOS设备更改方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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