我正在开发一个基于UITabBarController和UIViewController的iPhone应用程序,每个页面都有一个对应的视图控制器。该应用程序仅支持竖屏模式运行,因此每个视图控制器和应用委托都需要添加以下代码:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
在一个视图控制器中,当iPhone旋转到左横向时,我想弹出一个UIImageView。该图像的设计看起来是横向的,但宽度和高度为320x460(因此是纵向的)。
如何/应该手动检测这种类型的旋转,仅在此特定视图控制器中,在不对整个视图进行自动旋转的情况下?
Thomas
更新:
谢谢!我在viewDidLoad中添加了以下监听器:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)name:UIDeviceOrientationDidChangeNotification object:nil];
didRotate方法看起来像这样:
- (void) didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft)
{
//your code here
}
}