讓試試這個: 第一內側viewDidLoad
功能使用此代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
然後,我是創建將接收通知的兩行代碼的功能:
- (void)orientationChanged:(NSNotification *)object{
NSLog(@"orientation change");
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation == UIInterfaceOrientationPortraitUpsideDown){
if(deviceOrientation ==UIInterfaceOrientationPortrait){
NSLog(@"Changed Orientation To Portrait");
// Handle your view.
}
}else{
if(deviceOrientation ==UIInterfaceOrientationLandscapeLeft){
NSLog(@"Changed Orientation To Landscape left");
// Handle your view.
}else{
NSLog(@"Changed Orientation To Landscape right");
// Handle your view.
}
}
}
我希望我的答案會有所幫助。乾杯。
來源
2012-12-16 13:41:26
IKQ
你看過'UIViewController'的文檔嗎?它有一整節討論支持輪換的變化。關於這個確切的話題也有許多現有的問題。請做一些搜索。 – rmaddy
請參閱http://stackoverflow.com/questions/12780925/handling-rotation-in-ios6 – rmaddy