2012-10-27 17 views

回答

5

iOS 5和iOS 6調用不同的方向和旋轉代表。在iOS 5中,執行:

shouldAutorotateToInterfaceOrientation:,這是iOS中棄用6

所以,在iOS 6中,確保你設定一個根視圖控制器,並執行:

shouldAutorotate :, supportedInterfaceOrientations並支持InterfaceInterfaceOrientationsForWindow:

0

我有一個類似的問題。您可以檢查這個問題的答案:

Rotation behaving differently on iOS6

總之,有自轉中的iOS 5和iOS 6,並處理PortraitUpsideDown方向完全工作,我不得不實現自定義的UINavigationController並將其分配給self.window.rootViewController中的應用代理didFinishLaunchingWithOptions方法。

0

shouldAutorotateToInterfaceOrientation在ios6中已棄用。

所以如果你wnat上運行兩個操作系統版本的應用程序,然後添加shouldAutorotateToInterfaceOrientation過如下

//for ios6 
- (BOOL)shouldAutorotate { 

     UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation]; 

     if (orientation == UIInterfaceOrientationLandscapeLeft ||orientation == UIInterfaceOrientationLandscapeRight) 
{ 

      return YES; 
     } 
     return NO; 
     } 

//for ios5 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    //interfaceOrientation == UIInterfaceOrientationLandscapeRight; 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 

     return YES; 
    } 
    return NO; 
} 
8
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)); 
} 

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

超越控制這兩個在所有的UIViewController子類方法......這會爲工作ios 6及更早版本

+1

請注意,此示例僅支持兩種狀態:「豎直」(縱向)和「倒置」(縱向豎起)。 – Gonen

-1

爲了支持ios5和ios6中的自動控制,我們需要在ios6的情況下提供回調。`[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

,我們需要調用

- (NSUInteger)supportedInterfaceOrientations { 
return UIInterfaceOrientationMaskPortrait; 

}

-(BOOL)shouldAutoRotate{ 
    return YES; 
    } 

對於iOS5的

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 

{ 回報((toInterfaceOrientation == UIInterfaceOrientationPortrait)||(toInt erfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)); }

+0

嗯...我沒有格式化這已經?不,這是另一個副本:所以請不要將完全相同的答案張貼在多個問題上:它不是很適合所有問題,或者問題是應該標記/關閉的重複問題。 – kleopatra

相關問題