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

发布于 2024-07-27 16:47:50 字数 580 浏览 5 评论 0原文

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

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

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

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

[[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight];

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

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

My application is quite simple, but I have some problems when it starts. I setted in the Info.plist to be landscaped, but it seems to ignore the order. In fact, when the app is loading the Simulator is landscaped, but then it returns in portrait mode.

This is the hierarchy of the views and controllers:

  • MainViewController (extends UITabBarController just to override shouldAutorotateToInterfaceOrientation:)
    • Three extended UITableViewControllers as tabs (also those have the shouldAutorotateToInterfaceOrientation correctly setted up).

If I kinda force the orientation of the device to Landscape with:

[[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight];

Then for an instant the Simulator flashes in portrait mode, and then it goes landscaped. The problem is that in this way, the auto-rotation animations gets started, which is something I cannot tollerate. I just want a fixed, landscaped application.

Any clues? Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书信已泛黄 2024-08-03 16:47:50

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

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(method)

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

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

Try the following. Not sure why it does not work for you

1) set the key UIInterfaceOrientation
to UIInterfaceOrientationLandscapeRight in your .plist file

2) override your UITabBarController shouldAutorotateToInterfaceOrientation() method; in the following the code only deals with tab zero and one, and only with one controller: if you have a navigation controller and you want to control different controllers that may be on the stack, you have to modify the code accordingly

- (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) setting

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

in your delegate's applicationDidFinishLaunching() method is only required for the simulator, not on a device

3) add the following shouldAutorotateToInterfaceOrientation(method) in your controllers

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

4) run the app on your device and verify that it works properly by using the Hardware menu item Rotate Left and Rotate Right. You should see the display in landscape-mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文