我最近不得不处理同样的问题,我的解决方案如下:
在您希望能够旋转的视图的 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;
}
}
我希望我能帮上一点忙。