2013-03-01 101 views
2

我有一個支持方向更改並相應旋轉的應用程序。我收聽UIApplicationWillChangeStatusBarOrientationNotification事件。現在在這個應用程序的加載過程中,我添加了一些視圖,並根據當前的方向在我的應用程序中設置它們。iOS5,iOS6,旋轉,任意觸發事件

在iOS 6中,此工作正常,應用程序響應並正常旋轉,因此用戶可以在橫向和縱向模式下加載代碼,並且代碼正常工作。

在iOS 5中,如果我以縱向模式加載應用程序,應用程序工作正常,並且一旦在縱向模式下完成該加載並且UI已對齊並調整大小,它將響應其他方向更改到landascape或肖像。我遇到的問題是這樣的:當以橫向模式加載iOS 5時,以及在平面上使用iOS 5實際鋪設設備以確保其橫向時,我會收到一個從橫向移動到縱向的OrientationNotification(雖然設備沒有改變)。

因此,在同一個實驗中的另一個設備iOS 6,加載正常,我沒有得到任何奇怪的旋轉變化事件沒有發生,但與iOS 5我得到它們!

任何想法?

我支持的方向不論是iOS的

- (BOOL)shouldAutorotate { 
    return YES; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation: 
            (UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation == UIInterfaceOrientationPortrait || 
      interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
      interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || 
      interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

回答

2

這聽起來像iOS 5的認爲事情應該是人像的話,其實,沒有物理取向(即平向上或向下)和iOS 6沒有按「T。爲了確定顯示內容的方向,可以使用實際的設備方向,當設備處於平面狀態時使用狀態欄方向。例如:

// Get a useful screen orientation. 
// If the device is physically in portrait or landscape then 
// that is the orientation. 
// If it is not, then it is probably flat on a table and use 
// the orientation of the status bar which should be set to 
// the last physical orientation. 
// 
// screen Orientation 
//------------------------------------------------------------ 
+ (UIDeviceOrientation) screenOrientation { 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    if (orientation!=UIInterfaceOrientationPortrait 
     && orientation!=UIInterfaceOrientationPortraitUpsideDown 
     && orientation!=UIInterfaceOrientationLandscapeLeft 
     && orientation != UIInterfaceOrientationLandscapeRight) { 
     // Not known at this time. Use the status bar orientation 
     orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
    } 
    return orientation; 
} 

我不知道這直接可以幫助你,但也許在你通知處理程序,你可以檢查,看看實際的狀態欄的方向是什麼。或者,通知和狀態欄方向更改的時間可能不起作用。