我剛剛在iOS 5.1下的應用程序中修復了這個問題。這是一個古老的問題,但我在這裏留下了後代,因爲我沒有看到任何人解決這個問題,但沒有應用CGAffineTransform代碼的gobs,也沒有解決真正的問題,即UIInterfaceOrientation和UIDeviceOrientation不同步。
在我的情況下,我只需要修正方向,當我從僅肖像的ViewController進入方向時,當設備在轉換之前被物理旋轉時進入縱向和橫向ViewController。
// The "Interface Orientation" and the "Device Orientation" can become separated in some cases.
// Make sure the view controller only supports the interface orientation for the current device rotation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
int deviceRotation = [[UIDevice currentDevice] orientation];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
if (deviceRotation == UIDeviceOrientationUnknown ||
deviceRotation == UIDeviceOrientationFaceUp ||
deviceRotation == UIDeviceOrientationFaceDown)
return YES;
if (deviceRotation != interfaceOrientation)
return NO;
else
return YES;
}
你是否在所有情況下返回NO?你的觀點應該至少支持1個方向。 – skorulis 2010-10-25 02:10:52