最近我必须处理同样的问题,我的解决方案是如下:查看的的UIViewController内
是要能够旋转添加一个通知处理器为UIDeviceOrientationDidChangeNotification
-(void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotateFromInterfaceOrientation)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
那么当然你需要实现你的didRotateFromInterfaceOrientation
方法。
该方法中你可以使用
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
我所做其次是评价我想视图中显示,基于取向
switch (orientation) {
case UIDeviceOrientationLandscapeLeft:
NSLog(@"UIDeviceOrientationLandscapeLeft");
[self presentModalViewController:LandscapeView animated:YES];
break;
case UIDeviceOrientationLandscapeRight:
NSLog(@"UIDeviceOrientationLandscapeRight");
[self presentModalViewController:LandscapeView animated:YES];
break;
case UIDeviceOrientationPortraitUpsideDown:
NSLog(@"UIDeviceOrientationPortraitUpsideDown");
[LandScapeview dismissModalViewControllerAnimated:YES];
break;
case UIDeviceOrientationPortrait:
NSLog(@"UIDeviceOrientationPortrait");
[LandscapeView dismissModalViewControllerAnimated:YES];
break;
case UIDeviceOrientationFaceUp:
NSLog(@"UIDeviceOrientationFaceUp");
break;
case UIDeviceOrientationFaceDown:
NSLog(@"UIDeviceOrientationFaceDown");
break;
default:
break;
}
}
我希望我能帮助当前方向一点点。
哦,不要忘记删除通知处理程序,如果视图中消失... \t [NSNotificationCenter defaultCenter] removeObserver:自 \t \t \t \t \t \t \t \t \t \t \t \t \t名:@ “UIDeviceOrientationDidChangeNotification” \t \t \t \t \t \t \t \t \t \t \t \t object:nil]; – samsam 2010-05-06 07:29:31
我只是想检查一下,我明白了,我会留下所有其他的意见,因为不支持风景&然后你的代码将确保方向改变消息仍然可以收到的旋转视图控制器,我是否正确? – 2010-05-06 07:54:04
是的,这是正确的。我有同样的问题:5个纵向视图(每个都是一个NavigationController的“根视图”并且连接到TabBar)...除了应该改变旋转角度的那个外,你可以保留所有这些视图。我实现了一个Cover-Flow-View,在更改设备旋转时显示,它工作得很好。 – samsam 2010-05-06 09:46:34