UITabbar 的下半部分对点击没有反应 [英] Bottom half of UITabbar is not responding to clicks

查看:38
本文介绍了UITabbar 的下半部分对点击没有反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含 3 个项目的 UITabbar 并将其放置在 UIScrollView 上

I have created a UITabbar with 3 items and placed it on a UIScrollView

当我点击标签栏的按钮时,它们在下半部分没有响应.上部区域工作正常.单击选项卡栏正上方的区域时,选项卡也会切换.

When I click the buttons of the tabbar they do not respond in the bottom half. The upper area is working fine. When clicking in the area just above the tabbar the tabs are also switched.

有什么问题?如何纠正可点击按钮区域的这种错位?

What can be wrong? How can i correct this misalignment of the clickable button area?

在 viewDidLoad 中:

In viewDidLoad:

[super viewDidLoad];
scroll.frame = CGRectMake(0, 20, 320, 460);
scroll.pagingEnabled = YES;
scroll.contentSize = CGSizeMake(320 * 2, 460);
scroll.showsHorizontalScrollIndicator = NO;
scroll.showsVerticalScrollIndicator = NO;
scroll.scrollsToTop = NO;
scroll.delegate = self;
scroll.pagingEnabled = YES; 
viewNavController1 = [[viewNavController1 alloc] init];
ctrl = [[UITabBarController alloc] init];   

ViewController1 *viewC1= [[ViewController1 alloc] initWithNibName:@"ViewController1" bundle:nil];
UINavigationController *control = [[UINavigationController alloc] initWithRootViewController:viewC1];
viewC1.title = @"Title1";
[viewC1 release];

ViewController2 *viewC2 = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
UINavigationController *control2 = [[UINavigationController alloc] initWithRootViewController:viewC2];
viewC2.title = @"Title2";
[viewC2 release];   

UINavigationController *control3 = [[UINavigationController alloc] init];
ViewController3 *viewC3 = [[ViewController3 alloc] initWithNibName:@"ViewController3" bundle:nil];
[control3 pushViewController:viewC3 animated:NO];
viewC3.title = @"Title3";
[viewC3 release];

[ctrl setViewControllers:[NSArray arrayWithObjects:control,control2,control3,nil]];


CGRect frame = scroll.frame;
frame.origin.x = frame.size.width * 0;
frame.origin.y = 0;
viewNavController1.view.frame = frame;

viewC4 = [[ViewController4 alloc] initWithNibName:@"ViewController4" bundle:nil];
[viewNavController1 pushViewController:viewC4 animated:NO];
[scroll addSubview:viewNavController1.view];

frame = scroll.frame;
frame.origin.x = frame.size.width * 1;
frame.origin.y = 0;
ctrl.view.frame = frame;
[scroll addSubview:ctrl.view];

[scroll scrollRectToVisible:CGRectMake(320, 0, 320, 460) animated:NO];  

UITabBarItem *itm = [ctrl.tabBar.items objectAtIndex:0];
itm.image = [UIImage imageNamed:@"img1.png"];

itm = [ctrl.tabBar.items objectAtIndex:1];
itm.image = [UIImage imageNamed:@"img2.png"];

itm = [ctrl.tabBar.items objectAtIndex:2];
itm.image = [UIImage imageNamed:@"img3.png"];
[control release];
[control2 release];
[control3 release];

推荐答案

问题是 UITabbarController 没有将其视图添加为窗口的根视图.它显然假设.所以我不得不用它来欺骗它:

The problem was that the UITabbarController did not have its view added as the root view of the windows. Which it apparently assumes. so I had to trick it using:

[vc setWantsFullScreenLayout:YES];

vc 是主 ViewController 持有包含 UITabbarController 的滚动视图.

vc is the main ViewController holding the scrollview containing the UITabbarController.

有关更多说明,请参阅UIWindow addSubview 上的偏移.

See Offset on UIWindow addSubview for more explanations.

这篇关于UITabbar 的下半部分对点击没有反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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