在UIViewController實現中,我重寫了shouldAutorotateToInterfaceOrientation方法並返回YES(或TRUE)。此外,我重寫了這個方法:在模擬器中旋轉視圖不起作用
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
image.frame = CGRectMake(448, 381, 128, 113);
progresView.frame = CGRectMake(448, 498, 130, 11);
activityIndicator.frame = CGRectMake(448, 514, 20, 20);
statusLabel.frame = CGRectMake(473, 534, 97, 18);
} else {
image.frame = CGRectMake(335, 643, 128, 113);
progresView.frame = CGRectMake(335, 760, 130, 11);
activityIndicator.frame = CGRectMake(335, 776, 20, 20);
statusLabel.frame = CGRectMake(360, 776, 97, 18);
}
}
但是,當我在模擬器或設備上播放應用,旋轉不起作用。它僅以肖像模式顯示。我究竟做錯了什麼?有任何想法嗎?
P.S.我使用XCode 4.0.2和應用程序是爲iPad
我只是想說明你可以使用UIDeviceOrientationIsLandscape宏,而不是自己檢查LandscapLeft和LandscapeRight。 [UIKit函數參考](http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIKitFunctionReference/Reference/reference.html) – 2011-06-09 14:15:08