显示当不应该的风景视图

时间:2010-09-09 14:59:05

标签: iphone uiviewcontroller landscape

我只想问其他人是否也遇到此问题;

以前,标签栏应用默认情况下不允许使用横向视图,除非它已针对应用中的所有视图启用,但可以添加

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotateFromInterfaceOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

捕捉定向更改消息&然后相应地对消息作出反应。

最近我看到,一旦显示了风景视图,每个不允许风景的视图都会在手机倾斜时显示之前的风景视图。

所以, View1(不支持横向)倾斜手机显示View1侧身, View2(支持横向)倾斜手机显示Landscapeview2, 现在景观视图已经显示一次, View1倾斜显示Landscapeview2

我在presentModalViewController之后释放viewcontroller,并在不再需要横向视图时解除viewcontroller,因此它应该消失,但是在第一次显示后它会继续显示任何方向更改,就像再次调用presentModalViewController一样。

有什么想法吗?还有其他人有同样的问题吗? (它从未发生在3.x操作系统版本中)

1 个答案:

答案 0 :(得分:0)

对任何感兴趣的人; 看起来景观启用的视图控制器仍然作为方向更改的观察者,即使它不再是活动视图,基本上它是回答每个视图的更改。

我的解决方案是创建2个新的BOOL,1个名为isActiveView,1个名为isShowingLandscape,并使用这些来确保视图控制器仅在显示它或它的横向视图时响应。

相关代码是:

-(void)viewDidAppear:(BOOL)animated
{
  isActiveView = TRUE;
}

-(void)viewDidDisappear:(BOOL)animated
{
  isActiveView = FALSE;
}

-(void)didRotateFromInterfaceOrientation
{
  if ((orientation == UIDeviceOrientationPortrait) && ((isActiveView) || (showingLandscape)))
  {
    [self dismissModalViewControllerAnimated:YES];
    showingLandscape = FALSE;
  }
  else if ((orientation == UIDeviceOrientationLandscapeLeft) && (isActiveView))
  {
    LandscapeViewController *landscapeViewControllerObject = [[LandscapeViewController alloc] initWithNibName:@"LandscapeView" bundle:[NSBundle mainBundle]];
    [self presentModalViewController:landscapeViewControllerObject animated:YES];
    [landscapeViewControllerObject release];
    showingLandscape = TRUE;
  }
  else if ((orientation == UIDeviceOrientationPortraitUpsideDown) && ((isActiveView) || (showingLandscape)))
  {
    [self dismissModalViewControllerAnimated:YES];
    showingLandscape = FALSE;
  }
  else if ((orientation == UIDeviceOrientationLandscapeRight) && (isActiveView))
  {
    LandscapeViewController *landscapeViewControllerObject = [[LandscapeViewController alloc] initWithNibName:@"LandscapeView" bundle:[NSBundle mainBundle]];
    [self presentModalViewController:landscapeViewControllerObject animated:YES];
    [landscapeViewControllerObject release];
    showingLandscape = TRUE;
  }
}

希望这有助于其他人遇到同样的问题。