UITabBar 求助,请尚未修复!

发布于 2024-10-17 14:34:17 字数 234 浏览 4 评论 0原文

我有一个 TabBar,其中设置了 2 个 viewController,还有一个 mainScreen 视图。我希望在应用程序启动时显示带有底部 TabBar 的主屏幕视图,并且仅在触摸 TabBar 后才切换到 TabBars viewControllers。

我的问题是,TabBars viewController 的视图只会显示,除非我将 TabBar 的视图设置为clearColor,然后显示主屏幕视图。

I have a TabBar with 2 viewControllers set to it, and a mainScreen view. What I want at application launch to display the mainScreen view w/ the TabBar at the bottom, and only switch to TabBars viewControllers once the TabBar is touched.

My problem is that the TabBars viewController's views will only be displayed, unless I set the views of the TabBar to clearColor, only then the mainScreen View is shown.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

じее 2024-10-24 14:34:18

好吧,您确实应该将 applicationDidFinishLaunching 代码放在这里,以帮助我们了解您的目标。

那么,他们的想法是他们永远无法回到“主屏幕视图”?这有点奇怪,但我想你可以监视 tabBar,当他们按下它时,你会删除主屏幕。所以你的主应用程序委托看起来像这样:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSLog(@"tab pressed");
    [self.mainScreen removeFromSuperview]; 
    self.mainScreen = nil;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Build your tab controller here (or load in mainwindow.xib)
    self.window.rootViewController = self.tabBarController;
    self.tabBarController.delegate = self;

    //now build your mainScreen (or get from mainwindow); for example...
    self.mainScreen = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-49)];
    self.mainScreen.backgroundColor = [UIColor blueColor];

    UIButton * temp = [[UIButton alloc] initWithFrame: CGRectMake(110, 60, 100, 20)];
    temp.backgroundColor = [UIColor redColor];    
    [mainScreen addSubview:temp];
    [temp release];

    //now put your mainscreen "over" your tabBar
    [self.tabBarController.view addSubview:mainScreen];

    [self.window makeKeyAndVisible];

    return YES;
}

Well, you really should put your applicationDidFinishLaunching code here to help us understand your goal.

So, the idea is they can never get back to the "mainScreen view"? It's a little odd, but I guess you could monitor the tabBar, and when they press it, you remove the mainScreen. So your main app delegate would look something like:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSLog(@"tab pressed");
    [self.mainScreen removeFromSuperview]; 
    self.mainScreen = nil;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Build your tab controller here (or load in mainwindow.xib)
    self.window.rootViewController = self.tabBarController;
    self.tabBarController.delegate = self;

    //now build your mainScreen (or get from mainwindow); for example...
    self.mainScreen = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-49)];
    self.mainScreen.backgroundColor = [UIColor blueColor];

    UIButton * temp = [[UIButton alloc] initWithFrame: CGRectMake(110, 60, 100, 20)];
    temp.backgroundColor = [UIColor redColor];    
    [mainScreen addSubview:temp];
    [temp release];

    //now put your mainscreen "over" your tabBar
    [self.tabBarController.view addSubview:mainScreen];

    [self.window makeKeyAndVisible];

    return YES;
}
So尛奶瓶 2024-10-24 14:34:18

我认为这意味着您的主屏幕视图位于层次结构中的 TabBar 视图下方。您可以将“mainScreen”视图添加为初始 tabBar 视图的子视图。

一旦用户与标签栏交互,您就可以简单地删除主屏幕视图。在您的标签栏委托中:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
   if ([viewController.tabBarItem.title isEqualToString:@"TitleOfFirstViewInTabBar"]) {
       [mainScreenView removeFromSuperview]; // Assuming mainScreenView is available
   }
}

I think this means your mainScreen view is below your TabBar view in the hierarchy. You could add your "mainScreen" view as a subView of your initial tabBar view.

Once the user interacts with the tab bar you can simply remove your mainScreen view. In your tab bar delegate:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
   if ([viewController.tabBarItem.title isEqualToString:@"TitleOfFirstViewInTabBar"]) {
       [mainScreenView removeFromSuperview]; // Assuming mainScreenView is available
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文