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

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

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

这一切都很好,我可以轻松地在视图控制器之间轻弹。但是,当我呈现模态视图控制器,然后将其关闭时,当前视图控制器的视图将变为全屏并覆盖我的标签栏!我已经尝试将自动调整遮罩设置为不调整大小,但是一直在发生。

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

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

但是当我这样做时,标签栏甚至可以在任何模态视图上方看到!这很奇怪。我觉得有些东西我不理解所以如果有人能解释我所缺少的东西,我将不胜感激!

谢谢,

麦克

有帮助吗?

解决方案 3

我设法找到一种更好的方法来控制标签栏的外观,只需将子视图插入标签控制器标签栏的顶部即可。这是一种享受!

其他提示

尝试设置

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

在控制器的viewWillAppear方法

试一试。我想你想要标签栏控制器中的动态视图控制器。

-(void)applicationDidFinishLaunching:(UIApplication *)application {

// Add the tab bar controller's current view as a subview of the window
tabBarController.delegate=self;
tabBarController=[[UITabBarController alloc] init];

mainDashBoard=[[DashBoard alloc] initWithNibName:@"DashBoard" bundle:nil];
mainSearchView=[[SearchView alloc] initWithNibName:@"SearchView" bundle:nil];
mainMoreView=[[MoreView alloc] initWithNibName:@"MoreView" bundle:nil];

UINavigationController *nvCtr0=[[[UINavigationController alloc] init] autorelease];
UINavigationController *nvCtr1=[[[UINavigationController alloc] initWithRootViewController:mainDashBoard] autorelease];
UINavigationController *nvCtr2=[[[UINavigationController alloc] initWithRootViewController:mainSearchView] autorelease];
UINavigationController *nvCtr3=[[[UINavigationController alloc] initWithRootViewController:mainMoreView] autorelease];
UINavigationController *nvCtr4=[[[UINavigationController alloc] init] autorelease];//[[[UINavigationController alloc] initWithRootViewController:nil] autorelease];

tabBarController.viewControllers=[NSArray arrayWithObjects:nvCtr0,nvCtr1,nvCtr2,nvCtr3,nvCtr4,nil];

nvCtr0.tabBarItem.enabled=NO;
nvCtr4.tabBarItem.enabled=NO;

[window tabBarController.view];
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top