如何使用TabBar旋转应用程序?

时间:2011-02-17 00:03:16

标签: xcode ipad tabbar

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

#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

2 个答案:

答案 0 :(得分:1)

解决: 我有同样的问题。
没有TabBar一切都很好,添加TabBar和旋转中断 我猜测响应者链或视图层次结构中存在某些内容 所以我准备提交一个bug。所以写了一个测试应用程序来向Apple演示(因为他们总是要求一个),并且它有效。万岁,但为什么?

这些是我在Apple文档中的发现。 来自适用于iOS的View编程指南。 拆分视图控制器 “拆分视图控制器必须始终是您创建的任何接口的根。” 因此,它们不应该嵌入TabBar视图中,尽管我知道在野外有一个解决方法。

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

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

我出错的地方是:我创建了所有的TabBar子视图,但还没有编写任何代码,因为我想让TabBar首先使用SplitView,因此我的一个Tab视图没有被更改默认。

答案 1 :(得分:1)

以下答案是正确的。如果要添加包含使用CoreDataTableView控制器(与CS193P课程一起使用)的选项卡,请务必添加允许任何方向的方法。如果没有,您的拆分视图将无法正常工作。