gpt4 book ai didi

iphone - 如何从 UIViewController 调用 tabbarviewcontroller?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:54:18 28 4
gpt4 key购买 nike

我有一个包含三个选项卡的基于选项卡栏的应用程序。现在,当设备从纵向旋转到横向时,它应该加载不同的 UIViewController 并且当应用程序模式从横向更改回纵向模式时,应该再次显示标签栏 Controller 。如何做到这一点?

最佳答案

我猜你可以用下面的方法解决这个问题。由于您有两个位于同一层级的不同 ViewController,因此有一个 ViewController 是有意义的,它管理这两个 ViewController 并根据方向显示相应的 ViewController。

肖像

  • 窗口
    • MyRootViewController(UIViewController 子类)
      • MyTabBarViewController(UITabBarViewController 子类)

风景

  • 窗口
    • MyRootViewController(UIViewController 子类)
      • MyPortraitViewController(UIViewController 子类)

现在您的 MyRootViewController 类会检测到任何旋转(请参阅 UIViewController 文档)并将其 View 更改为您的两个 ViewController 之一:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

// Set the view to the corresponding ViewController (Assuming they were already initialized)
if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
self.view = self.myTabBarViewController.view;
} else {
self.view = self.myPortraitViewController.view;
}
}

您还应该确保在您的应用程序启动/重新激活时显示正确的 ViewController。为此,您可以在 MyRootViewController 类中使用以下方法:

- (void)viewWillAppear:(BOOL)animated;

希望对你有帮助

关于iphone - 如何从 UIViewController 调用 tabbarviewcontroller?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8558554/

28 4 0
文章推荐: android - 以编程方式为 ActionBarDrawerToggle 图标设置动画
文章推荐: javascript - 使用 JQuery,如何使
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com