【问题标题】:Having a UITabBar while displaying a view not on the UITabBar?在显示不在 UITabBar 上的视图时有一个 UITabBar?
【发布时间】:2011-02-14 11:08:19
【问题描述】:

我在使用 UITabBar 时遇到了一些问题,并且在网上找不到任何关于该主题的内容。几乎我想显示一个视图(比如TestView)和一个包含其他视图的TabBar:绿色视图和红色视图。因此,最初我希望 TestView 在底部显示一个带有 2 个选项卡的 tabBar,一个用于绿色视图,一个用于红色视图,一旦触摸其中一个选项卡,就会显示适当的视图,但不会有选项卡用于测试视图

但这是 MainAppDelegate 代码和我得到的图片

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

//Create the TabBar VC and ButtonSelect VC
testView = [[TestViewController alloc] init];
tabBarController = [[UITabBarController alloc] init];

//Create the viewcontroller's For the TabBarController
UIViewController *gvc = [[GreenViewController alloc] init];
UIViewController *rvc = [[RedViewController alloc] init];

//Make a array to containing the two viewcontrollers (for TabBar)
NSArray *viewControllers = [NSArray arrayWithObjects:gvc, rvc, nil];

//Attach the VC's to the TabBar
[tabBarController setViewControllers:viewControllers];

//Set to window
[window addSubview:[tabBarController view]];
[window addSubview:[testView view]];


[window makeKeyAndVisible];

[rvc release];
[gvc release];

return YES;

}

我得到的是This..

请帮忙

【问题讨论】:

    标签: iphone objective-c uiviewcontroller uitabbarcontroller tabbar


    【解决方案1】:

    调整 testView 的框架。例如,

    testView = [[TestViewController alloc] initWithFrame: CGRectMake( 0.0, 20.0, 320.0, 421.0)];

    我在这里使用了“幻数”,但您最好获取状态栏和标签栏的高度。


    到评论

    因此,您希望在用户选择其中一个选项卡时关闭测试视图。您可以通过将委托设置为 UITabBarController 并实现 tabBarController:didSelectViewController:` 方法来捕捉选择选项卡的时刻。基本上,您将在此方法中关闭测试视图。

    一种方法(并且无需过多更改代码)是将应用程序委托设置为 UITabBarController 的委托 (tabBarController.delegate = self;)。然后实现tabBarController:didSelectViewController:,从应用程序窗口中删除测试视图并执行tabBarController.delegate = nil;。

    【讨论】:

    • 好的,我已经修复了大小调整,但我仍然无法让 testViewController 默认显示其视图,并且只有在触摸 TabBar 时才会显示绿色和红色视图
    • 我在原始答案中为您的评论附加了解决方案。
    猜你喜欢
    • 2018-11-04
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多