奇怪的风景UITabBarController应用程序启动

时间:2009-07-17 00:06:45

标签: iphone cocoa-touch uitabbarcontroller landscape

我的应用程序非常简单,但启动时遇到了一些问题。我在Info.plist中设置了景观,但它似乎忽略了顺序。事实上,当应用程序加载时,模拟器会进行美化,但之后会以纵向模式返回。

这是视图和控制器的层次结构:

  • MainViewController(扩展UITabBarController只是为了覆盖shouldAutorotateToInterfaceOrientation :)
    • 三个扩展的UITableViewControllers作为选项卡(也正确设置了shouldAutorotateToInterfaceOrientation)。

如果我有点强迫设备的方向为横向:

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

然后,模拟器在纵向模式下闪烁,然后进行景观美化。问题是,通过这种方式,自动旋转动画开始,这是我无法容忍的。我只想要一个固定的景观应用程序。

任何线索?我错过了什么吗?

2 个答案:

答案 0 :(得分:0)

尝试以下方法。不知道为什么它对你不起作用

1)设置关键UIInterfaceOrientation
到.plist文件中的UIInterfaceOrientationLandscapeRight

2)覆盖你的UITabBarController shouldAutorotateToInterfaceOrientation()方法;在下面的代码中只处理选项卡零和一,并且只处理一个控制器:如果你有一个导航控制器并且你想控制可能在堆栈上的不同控制器,你必须相应地修改代码

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    BOOL tabZeroController = [[[self.viewControllers objectAtIndex:0] visibleViewController] isKindOfClass:[YourTabZeroTableViewController class]];

    BOOL tabOneController = [[[self.viewControllers objectAtIndex:1] visibleViewController] isKindOfClass:[YourTabOneTableViewController class]];


    if(self.selectedIndex == 0 && tabZeroController)
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

    if(self.selectedIndex == 1 && tabOneController)
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

    return NO;

}

2)设置

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

在你的委托的applicationDidFinishLaunching()方法只需要模拟器,而不是在设备上

3)在控制器中添加以下shouldAutorotateToInterfaceOrientation(方法)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
   return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

4)在您的设备上运行应用程序,并使用“硬件”菜单项“向左旋转”和“向右旋转”验证其是否正常工作。您应该以横向模式看到显示。

答案 1 :(得分:0)