2010-11-19 8 views
0

J'ai créé un UITabBar avec 3 articles et placé sur un UIScrollViewmoitié inférieure de UITabBar ne répond pas aux clics

Lorsque je clique sur les boutons de la barre d'onglets, ils ne répondent pas dans la moitié inférieure. La zone supérieure fonctionne correctement. Lorsque vous cliquez dans la zone située juste au-dessus de la barre d'onglets, les onglets sont également activés.

Qu'est-ce qui ne va pas? Comment puis-je corriger ce désalignement de la zone du bouton cliquable?

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

Répondre

2

Le problème était que le UITabBarController n'a pas ajouté son point de vue que la vue racine des fenêtres. Ce qu'il suppose apparemment. donc je devais le tromper en utilisant:

[vc setWantsFullScreenLayout:YES]; 

vc est la principale ViewController tenant la scrollview contenant le UITabBarController. Pour plus d'explications, voir Offset on UIWindow addSubview.

+0

Donc concis, si beau, si exactement la solution à mon problème. J'ai eu window-> MainVC-> TabController, et la moitié inférieure des onglets ne pouvait pas être cliqué. C'est le truc. S'il vous plaît, choisissez ceci en premier, Google. – CBGraham

Questions connexes