自定义视图作为tabbar,pushViewController无法正常工作

时间:2013-01-08 10:34:47

标签: iphone xcode

使用自定义视图作为标签栏,它在委托中声明,以便它可以在所有视图上使用。但问题是pushViewController没有在那里实现。我正在使用自定义视图在底栏上获取导航控制器动画,因为这不能在标签栏上实现。那么,我如何将pushViewController执行到条形按钮。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.homeViewController = [[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil] autorelease];

navController = [[UINavigationController alloc]initWithRootViewController:self.homeViewController];

navController.navigationBar.barStyle = UIBarStyleBlack;

[self.window addSubview:self.navController.view];

AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;   [appDelegate addCustomBottomBar];

[self.window makeKeyAndVisible];
return YES;
}

-(void)addCustomBottomBar{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];

viewBotBar = [[UIView alloc]initWithFrame:CGRectMake(0, 402, 320, 79)];
viewBotBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"1aa.png"]];
[self.window addSubview:viewBotBar];
[self.window bringSubviewToFront:viewBotBar];

[UIView commitAnimations];

UIButton *btnHome = [UIButton buttonWithType:UIButtonTypeCustom];
btnHome.frame = CGRectMake(0, 25, 54, 50);
[btnHome setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[btnHome addTarget:self action:@selector(home) forControlEvents:UIControlEventTouchUpInside];
[viewBotBar addSubview:btnHome];

UIButton *btnLoc = [UIButton buttonWithType:UIButtonTypeCustom];
btnLoc.frame = CGRectMake(58, 25, 63, 50);
[btnLoc setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[btnLoc addTarget:self action:@selector(loc) forControlEvents:UIControlEventTouchUpInside];
[viewBotBar addSubview:btnLoc];

UIButton *btnSer = [UIButton buttonWithType:UIButtonTypeCustom];
btnSer.frame = CGRectMake(124, 25, 63, 50);
[btnSer setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[btnSer addTarget:self action:@selector(ser) forControlEvents:UIControlEventTouchUpInside];
[viewBotBar addSubview:btnSer];

UIButton *btnBook = [UIButton buttonWithType:UIButtonTypeCustom];
btnBook.frame = CGRectMake(190, 25, 63, 50);
[btnBook setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[btnBook addTarget:self action:@selector(book) forControlEvents:UIControlEventTouchUpInside];
[viewBotBar addSubview:btnBook];

UIButton *btnMore = [UIButton buttonWithType:UIButtonTypeCustom];
btnMore.frame = CGRectMake(256, 25, 62, 50);
[btnMore setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[btnMore addTarget:self action:@selector(more) forControlEvents:UIControlEventTouchUpInside];
[viewBotBar addSubview:btnMore];


btnDwn = [UIButton buttonWithType:UIButtonTypeCustom];
btnDwn.frame = CGRectMake(135, 0, 45, 28);
[btnDwn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[btnDwn addTarget:self action:@selector(down) forControlEvents:UIControlEventTouchUpInside];
btnDwn.tag = 1;
[viewBotBar addSubview:btnDwn];
}

-(void)down
{
if (btnDwn.tag == 1) {
    // perform your required functionality
    btnDwn.tag = 2;

    CGRect newFrameSize = CGRectMake(0, 452, 320, 28);
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.0];
    viewBotBar.frame = newFrameSize;
    viewBotBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bottom-hidden.png"]];
   // self.tabController.tabBar.hidden = YES;
    [UIView commitAnimations];

}
else if (btnDwn.tag == 2) {
    // perform your required functionality
    btnDwn.tag = 1;

    CGRect newFrameSize = CGRectMake(0, 402, 320, 79);
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.0];

    viewBotBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"1aa.png"]];
    viewBotBar.frame = newFrameSize;
     //self.tabController.tabBar.hidden = NO;
    [UIView commitAnimations];
}
}

-(void)loc
{
LocationViewController *location = [[LocationViewController alloc]init];
[self.navigationController pushViewController:location animated:YES];
}

-(void)ser
{
ServicesViewController *services = [[ServicesViewController alloc]initWithNibName:@"ServicesViewController" bundle:nil];
[self.navigationController pushViewController:services animated:YES];
}

-(void)book
{
BookingViewController *book = [[BookingViewController alloc]initWithNibName:@"BookingViewController" bundle:nil];
[self.navigationController pushViewController:book animated:YES];
}

-(void)more
{
MoreViewController *more = [[MoreViewController alloc]initWithNibName:@"MoreViewController" bundle:nil];
[self.navigationController pushViewController:more animated:YES];
}

1 个答案:

答案 0 :(得分:1)

使用

self.window.rootViewController = self.navController;

而不是

[self.window addSubview:self.navController.view];

请参阅这些自定义UITabBar演示链接..

  1. Many Demos

  2. PeekabooTabBarController