视图控制器和视图的自定义 UITabBarController 问题 [英] Custom UITabBarController Problems with View Controllers and Views

查看:35
本文介绍了视图控制器和视图的自定义 UITabBarController 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个自定义 UITabBarController 以便我可以完全控制标签栏的外观.我已经完成了所有工作,所以我有一组它处理的视图控制器.

I'm writing a custom UITabBarController so I can fully control appearance of the tab bar. I've got it all working so I have an array of view controllers that it handles.

控制器有一个填充屏幕的主视图,在它的底部有一个 UIView 用于标签栏.该标签栏视图为每个视图控制器都有一个按钮.按下按钮时,我将视图控制器的视图添加到主视图,并设置它的框架,使其不覆盖选项卡栏视图:

The controller has a main view which fills the screen, and inside it it has a UIView at the bottom for the tab bar. That tab bar view has a button for each view controller. When buttons are pressed I add the view controller's view to the main view, and set it's frame so that it doesn't cover the tab bar view:

controller.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - kTabBarHeight);

这一切正常,我可以在视图控制器之间轻弹.然而,当我呈现一个模态视图控制器,然后关闭它时,当前视图控制器的视图变成全屏并覆盖我的标签栏!我已经尝试将自动调整大小蒙版设置为不调整大小,但一直在发生.

This all works fine, and I can flick between the view controllers just fine. However, when I present a modal view controller, and then dismiss it, the current view controller's view becomes full screen and covers up my tab bar! I've tried setting the autoresizing masks to not resize, but is keeps happening.

我还尝试使用以下方法将视图控制器视图添加到底部(标签栏下方):

I have also tried adding the view controllers view's to the bottom (below the tab bar) by using:

[self.view insertSubview:controller.view atIndex:0];

但是当我这样做时,标签栏甚至在任何模态视图上方都是可见的!这很奇怪.我想有些东西我不明白,所以如果有人能解释我遗漏的东西,我将不胜感激!

But when I do that, the tab bar is even visible above any modal views! Which is strange. I think there's something I'm not understanding so I would be grateful if someone can explain what I'm missing!

谢谢,

迈克

推荐答案

我找到了一种更好的方法来控制选项卡栏的外观,只需将子视图插入到选项卡控制器选项卡栏的顶部即可.这是一种享受!

I've managed to find a better way to control the appearance of the tab bar by simply inserting subviews to the top of the tab controllers tab bar. It's worked a treat!

这篇关于视图控制器和视图的自定义 UITabBarController 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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