2011-07-11 73 views
0

我有一个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度旋转。所以基本上它显示肖像的内容,而不是使用景观模式(实际上是你持有设备的方式)的模式..

我希望这是有道理的,有人能告诉我是什么导致了这。

截图,以使其更清晰:

回答

1

此时

- (BOOL)shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)interfaceOrientation 

你告诉你支持什么样的方向视图控制器。该设备实际上并没有旋转,因此视图控制器intefaceOrientation属性仍然是portrait,所以当它被推入堆栈时,它认为设备是portrait

pseudo code 
shouldAutoRotate... // at this point self.interfaceOrientation == portrait 
        // you push your controller here so it loads when the property is 

我不知道这是否会工作得很好,但是最早我可以看到你可以把在

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
+0

的interfaceOrientation(因此self.interfaceOrientation)是一个只读变量使不起作用。使用** didRotateFromInterfaceOrientation **方法确实有效。我不知道这件事。谢谢! – Jules

+0

我知道这是一个只读属性,但我认为这是视图控制器在内部使用的内容,因此知道它何时被设置是很重要的,因此您可以选择最佳时间推动控制器。 –

+0

willrotateto ...状态可以帮助很多,如果你想改变位置/ x和y没有那些恼人的跳跃 –

相关问题