2014-01-30 147 views
0

我有一個特定的UIViewController,我想鎖定/強制它的方向爲僅橫向。在橫向模式下鎖定特定的UIViewController +強制橫向模式

這是我做的,到目前爲止,但沒有任何成功....我試圖得到這個工作對iOS 6的& 7.

我在做什麼錯?

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ 

// Return YES for supported orientations 
return UIInterfaceOrientationMaskLandscape; 

} 

- (BOOL)shouldAutorotate { 

return YES; 

} 

- (NSUInteger)supportedInterfaceOrientations{ 
if([AppConst isIPad]){ 
    return UIInterfaceOrientationMaskLandscape; 
} 
return UIInterfaceOrientationMaskLandscape; 
} 

//not ios6 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
if([AppConst isIPad]){ 
    return YES; 
} 
return interfaceOrientation == UIInterfaceOrientationLandscapeRight; 
} 
+0

你如何呈現這個'UIViewController'?是指使用'UINavigtaion'? – Buntylm

回答

0

的方法shouldAutorotateToInterfaceOrientation中的iOS 6棄用您要使用的方法,而不是supportedInterfaceOrientations。如果你也想在iOS 5或更早的版本上運行,那麼你需要實現這兩種方法。

您還應該實施shouldAutorotate方法。

+1

我正在實施shouldAutorotate ...但它不工作... –

-1

就刪除所有這些方法在您的視圖控制器,並使用此方法

-(void)viewDidAppear:(BOOL)animated{ 

[[UIDevice currentDevice] setValue: 
[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] 
          forKey:@"orientation"];} 

編碼快樂

相關問題