2009-02-10 47 views
7

我有一个基于标签栏的应用程序。如何将视图旋转到标签栏应用程序中的风景

我在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)); 
     } 
    } 
} 

但是所有的工作混乱。横向视图不能正确填充区域,并且控件位于错误的位置,与首先设计的不同。

而且,我还没有通过调用

setStatusBarHidden:(BOOL) 
上的UIApplication参考

,像这样找到了一种方法来隐藏一切......

回答

1

您可以隐藏状态栏。

- (void)applicationDidFinishLaunching:(UIApplication *)application { 

[application setStatusBarHidden:YES]; 

} 

要摆脱的TabBar的你可以在界面生成器插座引用到您的代码,并呼吁

[myUITabBar removeFromSuperview]; 

可能的工作,虽然我没有测试它,至于其他问题,我不是100%,没有解决过的问题。

1

好吧,这是据我把这个工作:

- (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?

1

当我看着iPod应用程序时,在我看来,TabBarController视图并未以任何方式被替换或修改。我认为tabbarcontroller视图和coverflow视图之间只是淡入淡出。

如果我是你,我会尝试(不知道这是否可能工作)与一个覆盖流控制器,其视图显示在tabBarController的视图顶部。如果会阻止tabBarController自动控制其视图,但是此时我会淡出其视图并淡入覆盖流视图,该视图仅为横向视图。

我不知道statusBar是否会有适当的行为,我让你理清了很多细节,但无论如何,我认为有两个单独的控制器,一个是好主意,一个在景观中显示,其他(tabBar)以纵向显示。

希望能帮助你。

1

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

我已经发布了一个关于苹果开发人员论坛上是否确实可行的查询,但尚未得到答复。

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

5

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

其基本思想是您可以通过通知检测设备的物理方位,然后以“模态”方式激活一个新的视图控制器并让它请求全屏。通过让shouldAutorotate ...仅在一个方向上返回YES,您可以禁用界面旋转,因为您正在使用通知手动执行所有操作。当你改变物理方向时,你的模态视图控制器可以被呈现或被解除。

+0

谢谢! – mobius 2011-10-30 19:49:22

相关问题