2010-11-19 51 views
0

我創建中的UITabBar一樣有3項,並把它放在一個UIScrollViewUITabbar的下半部分沒有響應點擊

當我點擊他們沒有在下半區響應的TabBar的按鈕。 上部區域工作正常。 當點擊標籤欄正上方的區域時,標籤也會被切換。

什麼可能是錯的? 我該如何糾正可點擊按鈕區域的錯位?

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

回答

2

的問題是,該的UITabBarController沒有其觀點添加窗口的根視圖。它顯然假設。 所以我只好用它來欺騙:

[vc setWantsFullScreenLayout:YES]; 

VC是主要的ViewController持有包含的UITabBarController滾動視圖。

有關更多說明,請參見Offset on UIWindow addSubview

+0

如此簡潔,如此美麗,正是我解決問題的方法。我有window-> MainVC-> TabController,並且標籤的下半部分不能被點擊。這是東西。請從現在開始挑選,Google。 – CBGraham 2012-05-25 17:41:13