【问题标题】:Landscape view showing when not supposed to不应该显示的横向视图
【发布时间】:2010-09-09 14:59:04
【问题描述】:

我只是想问问其他人是否也有这个问题;

过去,tabbar 应用默认不允许横向视图,除非它为应用中的所有视图启用,但可以添加

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

捕捉方向变化消息,然后对消息做出相应反应。

最近我看到,一旦显示了横向视图,当手机倾斜时,每个不允许横向的视图都会显示以前的横向视图。

所以, View1(不支持横向)倾斜手机侧向显示 View1, View2(支持横向)倾斜手机显示 Landscapeview2, 既然风景已经展示过一次, View1 倾斜显示 Landscapeview2

我在 presentModalViewController 之后释放视图控制器,并在不再需要横向视图时关闭视图控制器,因此它应该消失,但在第一次显示后它继续显示后的任何方向更改,就好像再次调用了 presentModalViewController。

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

【问题讨论】:

    标签: iphone uiviewcontroller landscape


    【解决方案1】:

    对于任何有兴趣的人; 即使不再是活动视图,启用横向的视图控制器似乎也一直作为方向变化的观察者,基本上它正在响应每个视图的变化。

    我的解决方案是创建 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;
      }
    }
    

    希望这可以帮助遇到同样问题的其他人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 1970-01-01
      • 2020-07-12
      相关资源
      最近更新 更多