2014-01-30 151 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"];} 

编码快乐

相关问题