Bottom half of UITabbar is not responding to click

2019-06-10 01:00发布

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?

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];

1条回答
混吃等死
2楼-- · 2019-06-10 01:36

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 is the main ViewController holding the scrollview containing the UITabbarController.

See Offset on UIWindow addSubview for more explanations.

查看更多
登录 后发表回答