当前位置:编程学习 > wap >>

关于ios6.0系统上tabbar 和 navigation同时布局出现的问题,求高手解答


这时刚刚进如app的视图效果。


这时是push视图后,返回后的效果。

代码如下:

 ContactViewController *contactViewController = [[ContactViewController alloc] initWithNibName:@"ContactViewController" bundle:nil];
    SMSViewController *SmsViewController = [[SMSViewController alloc] initWithNibName:@"SMSViewController" bundle:nil];
    SettingViewController *settingViewController = [[SettingViewController alloc] initWithNibName:@"SettingViewController" bundle:nil];
    ExpandViewController *expandViewController = [[ExpandViewController alloc] initWithNibName:@"ExpandViewController" bundle:nil];
    
    
    NSArray *viewItemArray = [[NSArray alloc] initWithObjects:contactViewController, SmsViewController, expandViewController, settingViewController, nil];
    
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.delegate = self;
    self.tabBarController.viewControllers = viewItemArray;
    [[self.tabBarController.tabBar.items objectAtIndex:0] setTitle:@"Contact"];
    [[self.tabBarController.tabBar.items objectAtIndex:1] setTitle:@"SMS"];
    [[self.tabBarController.tabBar.items objectAtIndex:2] setTitle:@"Expand"];
    [[self.tabBarController.tabBar.items objectAtIndex:3] setTitle:@"Setting"];
    
    CGRect frame = CGRectMake(0, 0, 320, 48);
    UIView *v = [[UIView alloc]initWithFrame:frame];
    [v setBackgroundColor:[UIColor brownColor]];
    [[self.tabBarController.tabBar.subviews objectAtIndex:0] removeFromSuperview];
    [self.tabBarController.tabBar insertSubview:v atIndex:0];
    [v release];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.tabBarController];
    CGRect frames = CGRectMake(0, 0, 320, 48);
    UIView *vw = [[UIView alloc]initWithFrame:frames];
    [vw setBackgroundColor:[UIColor brownColor]];
    
    [[nav.navigationBar.subviews objectAtIndex:0] removeFromSuperview];
    [nav.navigationBar insertSubview:vw atIndex:0];
    [vw release];

    self.window.rootViewController = nav;
    [nav release];
   // self.window.rootViewController = self.mainViewController;
    [self.window makeKeyAndVisible];
--------------------编程问答-------------------- 请问如何去掉第一个视图中的黑条? --------------------编程问答-------------------- 一般的创建顺序是:
tab controller包含 nav controller包含 view controller
而你刚好相反 --------------------编程问答--------------------     [self.window makeKeyAndVisible];后面加如下两句就解决了,原因还为分析。   
 [nav setNavigationBarHidden:YES];
    [nav setNavigationBarHidden:NO];
补充:移动开发 ,  iPhone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,