2013-05-06 69 views
0

我正在使用此代碼鎖定iOS應用程序的橫向模式。在iPad中鎖定橫向模式

#pragma mark Orientation handling 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown); 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown); 
} 

它在iPhone中正常工作,但它在iPad中無法正常工作。它不會鎖定橫向模式。

需要一些指導。

+0

你也可以只設置在Xcode中總結選項卡中的方位爲您的應用程序。 – 2013-05-06 15:59:04

+0

我需要他們的一些屏幕處於橫向模式。這就是爲什麼我以編程的方式來做這件事...... – lakesh 2013-05-06 16:02:06

+0

你有什麼結果?它是否自動旋轉? – 2013-05-06 16:03:27

回答

0

理想情況下,只需在摘要選項卡中將其設置爲註釋即可。如果你真的想在代碼中做到這一點,只有你在AppDelegate類中設置了rootViewController才能使用它。

1

此代碼是不正確:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown); 
} 

一個UIInterfaceOrientation不是UIInterfaceOrientationMask。嘗試這樣的事情,而不是:

return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 

話雖這麼說,如果你想你的應用程序鎖定到景觀模式,有多種其他的問題在這裏 - 例如,你的supportedInterfaceOrientations只列出肖像模式,而不是景觀!

+0

我的意思是防止風景模式出現.. – lakesh 2013-05-06 17:38:43

0

在iOS 6中使用:

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskLandscape; 
} 

如果你有NavigationController可以將方法添加到一個類別。

0

我用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
      interfaceOrientation == UIInterfaceOrientationLandscapeRight; 
} 
相關問題