【发布时间】:2011-07-11 18:29:52
【问题描述】:
我有一个 iPad 应用程序,可以在所有四种视图模式(纵向上/下和横向左/右)下使用。但在某个时刻,我有一个视图,我只想在 landscape 模式下看到。所以我在 UIViewController 中执行以下操作,这将触发查看纯横向视图的操作:
- (void) showProperty:(Property *) property {
if ([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft || [self interfaceOrientation] == UIInterfaceOrientationLandscapeRight) {
PropertyViewController *propertyView = [[PropertyViewController alloc] initWithNibName:@"PropertyViewController" bundle:[NSBundle mainBundle]];
propertyView.property = property;
[self.navigationController pushViewController:propertyView animated:YES];
[propertyView release];
propertyView = nil;
}
else {
RotateDeviceViewController *rotateView = [[RotateDeviceViewController alloc] initWithNibName:@"TabRotate" bundle: [NSBundle mainBundle]];
rotateView.property = property;
[self.navigationController pushViewController:rotateView animated:YES];
[rotateView release];
rotateView = nil;
}
}
这可以正常工作,因此当 iPad 处于横向模式时会显示所需的屏幕 (PropertyViewController),如果不是,它会显示 RotateDeviceViewController 向用户显示他/她应该正确旋转设备的消息查看屏幕。
因此,当用户随后将他/她的设备旋转到横向模式时,我想向他们展示正确的视图 (PropertyViewController)。所有这些都有效!
问题出现在这个 RotateDeviceViewController.. 我有以下内容:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
[self showProperty];
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
- (void) showProperty {
PropertyViewController *propertyView = [[PropertyViewController alloc] initWithNibName:@"PropertyViewController" bundle:[NSBundle mainBundle]];
propertyView.property = property;
[self.navigationController pushViewController:propertyView animated:YES];
[propertyView release];
}
因此,当我将设备(查看 RotateDeviceViewController 时)旋转到横向模式时,我会向用户显示 PropertyViewController。这行得通...但是当 PropertyViewController 出现时,它显示我的布局旋转了 90 度。所以基本上它以 portrait 模式显示内容,而不是使用 landscape 模式(这实际上是您拿着设备的方式)..
我希望这是有道理的,有人可以告诉我是什么原因造成的。
截图更清楚:
【问题讨论】:
标签: xcode ipad orientation rotation viewcontroller