我的UITabbar的下半部分没有响应。我找到了更多有问题的人,但没有解决方案。
我认为问题可能是由于我没有使用tabbar作为全屏应用程序,而只是屏幕的一部分(iPhone上的320 * 380)。但是,我使用自定义UITabbarController。这是在我的UITabbarController子类的构造函数之后:
-(void)addCustomElements
{
UIImageView *tabBarBackground = [[UIImageView alloc] initWithFrame:CGRectMake(0, 306, 320, 74)];
[tabBarBackground setImage:[UIImage imageNamed:@"Tab Bottom.png"]];
[self.view addSubview:tabBarBackground];
UIImage *buttonImage = [UIImage imageNamed:@"Places Tab.png"];
UIImage *selectedImage = [UIImage imageNamed:@"Places Tab Selected.png"];
btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
btn1.frame = CGRectMake(0, self.view.frame.size.height-42, 160, 44);
[btn1 setImage:buttonImage forState:UIControlStateNormal];
[btn1 setImage:selectedImage forState:UIControlStateSelected];
[btn1 setTag:0];
[btn1 setSelected:YES];
buttonImage = [UIImage imageNamed:@"Map Tab.png"];
selectedImage = [UIImage imageNamed:@"Map Tab Selected.png"];
btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
btn2.frame = CGRectMake(160, self.view.frame.size.height-42, 160, 44);
[btn2 setImage:buttonImage forState:UIControlStateNormal];
[btn2 setImage:selectedImage forState:UIControlStateSelected];
[btn2 setTag:1];
[self.view addSubview:btn1];
[self.view addSubview:btn2];
[btn1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[btn2 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
我这样创造它:
tabBarController = [[CustomTabbar alloc]init];
tabBarController.view.frame=CGRectMake(0, 0, 320, 380);
[tabBarController viewDidAppear:NO];
mapsView = [[MapView alloc]init];
placesView = [[FavoritesList alloc]init];
//Suggestions from another forum (didn't work):
//[mapsView setWantsFullScreenLayout:YES];
//[placesView setWantsFullScreenLayout:YES];
mapsView.title=@"Maps";
placesView.title=@"Places";
placesView.mapView=mapsView;
mapsView.favorites=placesView;
NSArray *controllers = [NSArray arrayWithObjects:placesView, mapsView, nil];
[tabBarController setViewControllers:controllers];
[self addSubview:tabBarController.view];
有人知道修复此问题吗?