2013-08-22 26 views
0

我需要:以編程方式將設備從縱向轉換爲兼容iOS6和iOS5的橫向。
問題:我不能在ios6上使用[UIDevice setOrientation]函數。更改與ios6和ios5兼容的設備方向

我有:對iOS6的代碼:

- (BOOL) shouldAutorotate 
{ 
    return YES; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeLeft; 
} 

對於iOS5的代碼:

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

所以,我需要寫上的iOS5旋轉代碼:

-(void)viewWillAppear:(BOOL)animated 
    { 
     [super viewWillAppear:animated]; 

     // [[UIDevice currentDevice] setOrientation] - I cannot use it 
     // ??? 
    } 

回答

0

我通過設置狀態欄的方向實現了這一點,嘗試在代碼中執行:

[[sharedApplication] setStatusBarHidden:YES]; 
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight]; 

當您需要縱向模式時,將狀態欄設置爲setStatusBarHidden:NO,並再次將狀態欄方向設置爲縱向UIInterfaceOrientationPortrait