我有一个iPad应用程序,可用于所有四种查看模式(纵向上/下和横向左/右)。但在某个时候我有一个观点,我只想在风景模式中看到。所以,我中的UIViewController以下将触发操作来查看的唯一景观视野:iPad:如何根据方向(横向/纵向)显示不同的屏幕
- (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;
}
}
这工作得很好,因此显示或者所需的屏幕(PropertyViewController)当iPad在横向模式举行,如果没有,则显示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度旋转。所以基本上它显示肖像的内容,而不是使用景观模式(实际上是你持有设备的方式)的模式..
我希望这是有道理的,有人能告诉我是什么导致了这。
截图,以使其更清晰:
的interfaceOrientation(因此self.interfaceOrientation)是一个只读变量使不起作用。使用** didRotateFromInterfaceOrientation **方法确实有效。我不知道这件事。谢谢! – Jules
我知道这是一个只读属性,但我认为这是视图控制器在内部使用的内容,因此知道它何时被设置是很重要的,因此您可以选择最佳时间推动控制器。 –
willrotateto ...状态可以帮助很多,如果你想改变位置/ x和y没有那些恼人的跳跃 –