0

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

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

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

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

[[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight];

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

有什么线索吗?我错过了什么吗?

4

2 回答 2

0

试试下面的。不知道为什么它不适合你

1)
在 .plist 文件中将键 UIInterfaceOrientation 设置为 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(method)

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

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

于 2009-07-17T08:11:35.850 回答
0

也许这可以帮助 http://www.dejoware.com/blogpages/files/iphone_programming_landscape_view_tutorial.html

于 2010-03-24T15:02:01.433 回答