xcode - 如何将视图锁定为纵向模式,但仍允许一个视图旋转? [英] xcode - How do I keep views locked into portrait mode, but still allow one view to rotate?

查看:152
本文介绍了xcode - 如何将视图锁定为纵向模式,但仍允许一个视图旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到设备轮换问题。除了一个视图,我显示公司启动画面,我想将所有剩余的应用程序视图锁定到纵向显示。在项目设置中,支持的方向是Portrait和LandscapeLeft。在公司飞溅中它工作正常,无论我如何旋转设备,视图旋转都被锁定在LandscapeLeft中。在我将设备向左旋转的所有其他视图中,视图会改变而不是保持纵向显示。这些方法甚至没有开火?如果我从项目中支持的方向中删除横向,则会拧紧公司启动视图。我尝试更改 shouldAutorotate 返回,但这没有帮助。试图通过这里发布的建议,但这没有救命。如果我将以下代码放入我的AppDelegate.m,一切都被锁定为纵向模式,并且公司启动在访问时崩溃。

I'm having a problem with device rotation. Except for ONE view, where I show a company splash screen, I want to lock all the remaining app views into Portrait display. In the project settings the supported orientations are Portrait and LandscapeLeft. In the 'Company Splash' it works fine and the view rotation is locked into LandscapeLeft no matter how I rotate the device. On all the other views when I rotate the device to the left the view alters instead of staying in portrait display. The methods are not even firing? If I remove Landscape left from the supported Orientations in the project, that screws up the 'Company Splash' view. I tried changing the shouldAutorotate return to NO, but that didn't help. Tried to work my way through the suggestions posted here, but that didn't help. If I put the following code into my AppDelegate.m, everything is locked into portrait mode and the 'Company Splash' crashes when accessed.

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

无论设备如何旋转,如何将视图锁定为纵向模式除了一个屏幕?

How do I lock the view into portrait mode no matter how the device is rotated except for the one screen?

**'公司启动'视图中的方法。再次,它应该是这样的。

** method from the 'Company Splash' view. Again, works like it is supposed to.

-(NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}

**来自所有其他视图的方法不希望他们

** methods from all the other views, which rotate out of portrait when I don't want them to

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // IOS5 Only returning that it should rotate to potrait
    return (interfaceOrientation == UIDeviceOrientationPortrait);
}

-(BOOL)shouldAutorotate
{
    // forcing the rotate IOS6 Only
    return YES;
}

-(NSInteger)supportedInterfaceOrientations
{
    // return number or enum IOS6 Only
    return UIInterfaceOrientationMaskPortrait;
}

我想也许是因为UITabBarController是根控制器而我' m在ViewController中吗?这些方法甚至没有触发?

I thought maybe it might be because a UITabBarController is the root controller and I'm in a ViewController off of that? The methods are not even firing?

推荐答案

将观察者添加到要旋转的视图的viewDidLoad方法中,如下所示: / p>

Add an observer to the viewDidLoad method of the view you want to rotate like this :

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
 addObserver:self selector:@selector(orientationChanged:)
 name:UIDeviceOrientationDidChangeNotification
 object:[UIDevice currentDevice]];

然后根据 orientationChanged 方法内的横向视图设置视图像这样:

and then set the views according the the landscape view inside the orientationChanged method like this :

- (void) orientationChanged:(NSNotification *)note{
UIDevice * device = [UIDevice currentDevice];
switch(device.orientation)
{
    case UIDeviceOrientationPortrait:

        break;
    case UIDeviceOrientationPortraitUpsideDown:

        break;
    case UIDeviceOrientationLandscapeLeft:

        break;
    case UIDeviceOrientationLandscapeRight:

        break;

    default:
        break;
  };
}

这篇关于xcode - 如何将视图锁定为纵向模式,但仍允许一个视图旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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