【问题标题】:How rotate view to landscape in a tabbar app如何在标签栏应用程序中将视图旋转为横向
【发布时间】:2010-10-06 18:31:13
【问题描述】:

我有一个基于标签栏的应用程序。

我在 Interface Builder 中构建了 2 个视图,一个是纵向的,另一个是横向的。

现在,我想要类似 iPod 应用程序的东西。我希望横向视图是全屏的,并隐藏标签栏和状态栏。

我做这个的基础:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                duration:(NSTimeInterval)duration { 
    if (self.landscape) {
        if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
        {
            self.view = self.portrait;
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(360));
        }
        else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        {
            self.view = self.landscape;
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
        }
        else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
        {
            self.view = self.landscape;
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
        }
        else
        {
            self.view = self.portrait;
            self.view.transform =  CGAffineTransformMakeRotation(degreesToRadian(-180));
        }
    }
}

但所有工作都很混乱。横向视图未正确填充该区域,并且控件位于错误的位置,与最初的设计不同。

另外,我仍然没有找到隐藏其他所有内容的方法......

【问题讨论】:

    标签: iphone ios cocoa-touch


    【解决方案1】:

    查看 Apple 的“AlternateViews”示例代码。

    基本思想是您可以通过通知检测设备的物理方向,然后“模态”激活一个新的视图控制器并让它请求全屏。您可以通过 shouldAutorotate... 仅针对一个方向返回 YES 来禁用界面旋转,因为您是通过通知手动完成所有这些操作的。当您更改物理方向时,您的模态视图控制器要么显示要么关闭。

    【讨论】:

      【解决方案2】:

      似乎有相当多的编码人员希望有一个标签栏项目将他们带到一个横向视图全屏(没有状态栏,没有标签栏)然后回来。

      我已经在苹果开发者论坛上发帖询问这是否真的可行,但还没有回复。

      为什么这么难? (对不起,一个新手问题?似乎一些相当明显的事情应该不难)我在网上找到的没有人对此有明确的答案。

      【讨论】:

        【解决方案3】:

        当我查看 iPod 应用程序时,在我看来 TabBarController 视图没有以任何方式被替换或修改。我认为tabbarcontroller 视图和coverflow 视图之间只有一个淡入淡出的过渡。

        如果我是你,我会尝试(不确定这是否可行)coverflow 控制器,它的视图显示在 tabBarController 的视图之上。 If 会阻止 tabBarController 自动旋转它的视图,但在那一刻我会淡出它的视图并淡入coverflow视图,这将只是横向的。

        我不知道 statusBar 是否会有适当的行为,我让很多细节让你理清,但无论如何我认为拥有两个独立的控制器是个好主意,一个显示横向,另一个(tabBar)纵向。

        希望对你有所帮助。

        【讨论】:

          【解决方案4】:

          好的,这就是我所做的工作:

          - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                          duration:(NSTimeInterval)duration {
              if (self.landscape) {
                  if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
                  {
                      self.view = self.portrait;
                      //self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(360));
                  }
                  else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
                  {
                      self.view = self.landscape;
                      //self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
                  }
                  else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
                  {
                      self.view = self.landscape;
                      //self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
                  }
                  else
                  {
                      self.view = self.portrait;
                      //self.view.transform =  CGAffineTransformMakeRotation(degreesToRadian(-180));
                  }
              }
          }
          

          现在,在 AppDelegate 中:

          - (void) didRotate:(NSNotification *)notification
          {   
              UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
              [UIView beginAnimations:nil context:NULL];  
          
              if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
              {
                  [tabBarController.view setAlpha:0.0];
                  [tabBarController.view removeFromSuperview];
          
                  [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]; 
              } else {
                  [tabBarController.view setAlpha:1.0];
                  [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];      
              }
              [UIView commitAnimations];  
          }
          

          那么如何设置当前视图以及如何恢复tabbar呢?

          【讨论】:

            【解决方案5】:

            你可以通过调用隐藏状态栏

            setStatusBarHidden:(BOOL)
            

            在 UIApplication 参考上,像这样。

            - (void)applicationDidFinishLaunching:(UIApplication *)application {
            
            [application setStatusBarHidden:YES];
            
            }
            

            要摆脱标签栏,您可以在 Interface builder 中为您的代码创建一个引用出口并调用

            [myUITabBar removeFromSuperview];
            

            这可能可行,虽然我没有测试过,至于其他问题,我不是 100%,以前没有解决过这些问题。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-08-25
              • 1970-01-01
              • 2016-03-04
              • 2015-05-30
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多