如何使用TabBar旋转应用程序? [英] How to rotate app with TabBar?

查看:83
本文介绍了如何使用TabBar旋转应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个splitview应用程序正常工作,直到我在rootview部分添加一个TabBar。问题是,当我将TabBar添加到rootview时,应用程序不会旋转到横向,如果我更改方向,视图将保持纵向模式。
我该如何解决这个问题?希望你能帮忙

Hi I have a splitview app that is working fine until I add a TabBar in the rootview section. The problem is that when I add the TabBar to the rootview the app does not rotate to landscape, if I change the orientation the view remains in portrait mode. How can I solve this?. Hope you can help

#import "SplitViewTest3AppDelegate.h"
#import "SISACWelcomeViewController.h"

@implementation SplitViewTest3AppDelegate

@synthesize window, masterViewController, splitViewController,masterViewTabBarController, searchViewController;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStyleGrouped];
    UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
    masterNavigationController.tabBarItem.image = [UIImage imageNamed:@"Folder.png"];

    //NewsFeedsNavigationController *newsFeedsNavigationController = [[NewsFeedsNavigationController alloc] init];
    SISACWelcomeViewController *sisacWelcomeViewController = [[SISACWelcomeViewController alloc] init];
    UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:sisacWelcomeViewController];

    searchViewController = [[UIViewController alloc] initWithNibName:@"SearchView" bundle:nil];
    searchViewController.tabBarItem.image = [UIImage imageNamed:@"Search-icon.png"];

    masterViewTabBarController = [[UITabBarController alloc] init];
    masterViewTabBarController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, searchViewController, nil];

    masterViewController.detailNavigationController = detailNavigationController;

    splitViewController = [[UISplitViewController alloc] init];

    splitViewController.viewControllers = [NSArray arrayWithObjects:masterViewTabBarController, detailNavigationController, nil];

    splitViewController.delegate = sisacWelcomeViewController;

    // Add the split view controller's view to the window and display.
    [window addSubview:splitViewController.view];
    //[masterNavigationController.view addSubview:tab.view];
    [window makeKeyAndVisible];

    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive.
     */
}

- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     */
}

#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}

- (void)dealloc {
    [window release];
    //[tab release];
    [super dealloc];
}

@end


推荐答案

已解决:
我有同样的问题。

如果没有TabBar一切都很好,添加TabBar和轮换中断。

我猜我有在响应者链或视图层次结构中被破坏的东西。

所以我准备提交一个bug。所以写了一个测试应用程序给Apple演示(因为他们总是要求一个),并且它有效。万岁,但为什么?

SOLVED: I had the same issue.
Without the TabBar all is well, add the TabBar and the rotation breaks.
I guessed that there is something broken in the responder chain or view hierarchy.
So I was about to submit as a bug. So wrote a test app to demo to Apple (because they ALWAYS ask for one), and it worked. Hooray, but why?

这些是我在Apple文档中的发现。
来自适用于iOS的View Programming Guide。
拆分视图控制器
拆分视图控制器必须始终是您创建的任何接口的根目录。
因此它们不应该嵌入TabBar视图中,虽然我知道有一个解决方法。

These are my findings from the Apple docs. From the View Programming Guide for iOS. Split View Controller "A split view controller must always be the root of any interface you create." Thus they should not be embedded within a TabBar View, although I understand that there is a workaround out in the wild.

另外:
创建标签栏界面
在拆分视图界面中将其安装为两个根视图之一。(仅限iPad)

Also: Creating a Tab Bar Interface "Install it as one of the two root views in a split view interface. (iPad only)"

解决方案:
经过更多的调查,以及一些反复试验,我发现了这个问题。
当然现在看起来很明显。
当SplitView测试shouldAutorotateToInterfaceOrientation时,它会测试整个层次结构上的每个可能的视图,即MasterView中的每个视图,因此TabBar中的每个视图,以及DetailView中的每个视图,因此当前NavigationStack中的每个视图。
美中不足的是,新创建的ViewController默认情况下不支持Landscape。

Solution: After much more investigation, and some trial and error, I found the issue. Of course it seems so obvious NOW. When the SplitView tests for shouldAutorotateToInterfaceOrientation, it tests every possible view on the whole hierarchy, that is EVERY view in the MasterView, thus EVERY view in the TabBar, and EVERY view in the DetailView, thus EVERY view in the current NavigationStack. The fly in the ointment is that a newly created ViewController does not support Landscape by default.

我出错的地方是:我创建了所有的TabBar子视图,但还没有编写任何代码,因为我想让TabBar首先运行SplitView,因此我的一个选项卡视图没有从默认值更改。

Where I had gone wrong was: I had created ALL of the TabBar subviews, but not written any more code yet, because I wanted to get the SplitView with TabBar working first, thus 1 of my Tab Views had not been changed from the default.

这篇关于如何使用TabBar旋转应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆