【问题标题】:How to rotate app with TabBar?如何使用 TabBar 旋转应用程序?
【发布时间】:2011-06-28 18:20:52
【问题描述】:

您好,在我在 rootview 部分添加 TabBar 之前,我有一个可以正常工作的 splitview 应用程序。问题是,当我将 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

【问题讨论】:

    标签: xcode ipad tabbar


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      已解决: 我有同样的问题。
      没有 TabBar 一切都很好,添加 TabBar 和旋转中断。
      我猜想响应者链或视图层次结构中有问题。
      所以我正要作为一个错误提交。所以写了一个测试应用程序来演示给苹果(因为他们总是要求一个),它工作。万岁,但为什么呢?

      这些是我在 Apple 文档中的发现。 来自 iOS 的 View Programming Guide。 拆分视图控制器 “拆分视图控制器必须始终是您创建的任何界面的根。” 因此,它们不应该嵌入到 TabBar 视图中,尽管我知道在野外有一种解决方法。

      还有: 创建标签栏界面 “将其安装为拆分视图界面中的两个根视图之一。(仅限 iPad)”

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

      我出错的地方是:我已经创建了所有的 TabBar 子视图,但还没有编写任何代码,因为我想先让带有 TabBar 的 SplitView 工作,因此我的选项卡视图中的 1 个没有从默认。

      【讨论】:

        猜你喜欢
        • 2012-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-15
        • 1970-01-01
        • 2011-11-14
        • 1970-01-01
        相关资源
        最近更新 更多