2013-01-16 19 views
0

我正在使用ios6版本來生成新的Ipad應用。在我的應用程序中,我創建了一個分割視圖。該分割視圖必須始終處於橫向模式。 App正在使用ipad 6.0模擬器。但不工作在iPad 5.0模擬器。我想運行應用程序都ipad 6.0和ipad 5.0。無法在ipad應用中設置方向

我使用這個代碼

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

-(BOOL) shouldAutorotate { 
    return NO; 
} 

回答

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]; 
    } 

UPDATE

可能人們在使用把此行中ViewWillApear檢查設備orientation像下面這樣: -

[[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只landscap你可以像波紋管那樣做:

-(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; 
    } 
0

在安裝iOS 5.0,你應該使用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return interfaceOrientation == UIInterfaceOrientationMaskLandscape; 
} 
+0

是如何在同一個應用程序中使用此代碼 – Goutham

+0

只需將它放在您的問題中描述的方法旁邊即可。 –

+0

我不認爲這會起作用。該行應該是:return(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); – Snowcrash

相關問題