0

我正在使用 ios6 版本来生成新的 Ipad 应用程序。在我的应用程序中,我正在创建一个拆分视图。该拆分视图必须始终处于横向模式。应用程序在 ipad 6.0 模拟器中运行。但不适用于 ipad 5.0 模拟器。我想同时运行 ipad 6.0 和 ipad 5.0 的应用程序。

我正在使用此代码

-(NSUInteger)supportedInterfaceOrientations
{
     return UIInterfaceOrientationMaskLandscape;
}

-(BOOL) shouldAutorotate {
     return NO;
}
4

2 回答 2

0

您可以像这样在 ios6 中进行操作:-

-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{

    return UIInterfaceOrientationMaskAll;
}

并每次检查ViewWillApear设备方向,例如:-

- (void)willRotateToOrientation:(UIInterfaceOrientation)newOrientation {
        if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
        {
            if (newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight) {

              //set your landscap View Frame
                [self supportedInterfaceOrientations];

            }



        }
        else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
        {
            if(newOrientation == UIInterfaceOrientationPortrait || newOrientation == UIInterfaceOrientationPortraitUpsideDown){
      //set your Potrait View Frame
                [self supportedInterfaceOrientations];

            }
        }
        // Handle rotation
    }


    -(void)viewWillAppear:(BOOL)animated
    {
        [self willRotateToOrientation:[[UIDevice currentDevice] orientation]];  
        [super viewWillAppear:YES];
    }

更新

很可能人们使用下面这样的检查设备orientation将这条线放入ViewWillApear:-

[[UIApplication sharedApplication] statusBarOrientation];
    [[UIDevice currentDevice] orientation];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceRotated:) name:UIDeviceOrientationDidChangeNotification object:nil];

-(void)deviceRotated:(NSNotification*)notification
{

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {
        //Do your stuff for landscap
    }
    else if(orientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
      //Do your stuff for potrait

    }

}

在 IOS5 中,你可以像下面这样做:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {


        return YES;
    }
    else
    {
        return NO;
    }
}

if you wish to support all oriantation you need to just return YES  like:-

 -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

            return YES;  
    }
于 2013-01-16T11:34:21.310 回答
0

在 iOS 5.0 中,您应该使用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return interfaceOrientation == UIInterfaceOrientationMaskLandscape;
}
于 2013-01-16T11:22:12.980 回答