当推送到其他视图控制器时隐藏uiimage



我正在将Uimageview添加为tabbarcontroller.view的子视图。当我推到其他视图控制器时,tabbarcontroller会被隐藏,但在推到其他类时图像会出现。在选项卡控制器中,所有选项卡项都是一个导航控制器。我没有在选项卡控制器中添加选项卡这是我的代码:

imgV=[[UIImageView alloc]initWithFrame:CGRectMake(0, 428, 320, 48)];
tabBarController = [[UITabBarController alloc] init];
tabBarController.moreNavigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; 
tabBarController.moreNavigationController.topViewController.view.backgroundColor=[UIColor clearColor];  
tabBarController.delegate=self;

//tabBarController.selectedIndex=0;

UIImage *img  = [UIImage imageNamed: @"home_selected.png"];
[imgV setImage:img];
//    [imgV setAlpha:0.5];
[self.tabBarController.view addSubview:imgV];
[self.tabBarController.view  bringSubviewToFront:imgV];
[imgV release];

Dashboard_iPhone *dash = [[Dashboard_iPhone alloc] init];
UINavigationController *tabItem0 = [[[UINavigationController alloc] initWithRootViewController:dash] autorelease];
tabItem0.view.backgroundColor=[UIColor clearColor];
    TrackProgram_iPhone *rep = [[TrackProgram_iPhone alloc] init];
UINavigationController *tabItem1 = [[[UINavigationController alloc] initWithRootViewController:rep] autorelease];
tabBarController.tabBarItem.title=@"TrackProgram";  
tabItem1.view.backgroundColor=[UIColor clearColor];

TrackClinic_iPhone *loc = [[TrackClinic_iPhone alloc] init];
UINavigationController *tabItem2 = [[[UINavigationController alloc] initWithRootViewController:loc] autorelease];
tabBarController.tabBarItem.title=@"TrackClinic ";
tabItem2.view.backgroundColor=[UIColor clearColor];

tabBarController.viewControllers=[NSArray arrayWithObjects:tabItem0,tabItem1,tabItem2,nil];

[self.view insertSubview:tabBarController.view belowSubview:dash.view ];    
[self presentModalViewController:tabBarController animated:NO];

当我推到其他类时

    -(void)logoutBtnTap
{
appDelegate.enterLogout=YES;
for(UIImageView *view in[self.view subviews])
{
    for(UIImage *img in view.subviews){//remove photoes from the subview
        [img removeFromSuperview]; 
    }
    [view removeFromSuperview];
}

Login_iPhone *controller=[[Login_iPhone alloc]init];
[controller setHidesBottomBarWhenPushed:YES];
[acctExec_iPhone.imgV removeFromSuperview];
acctExec_iPhone.imgV.hidden=YES;
[self.navigationController pushViewController:controller animated:YES];
[controller release];

}

我评论您以前的问题。

隐藏图像视图

beacuse hidesBottomBarWhenPushed=yes表示您的tabBarController隐藏选项卡而不查看。

需要注意的是,您需要添加到tabBar中的imageView,而不是视图。

当操作推送或弹出对象控制器时,此方法可能会发送到消息tabBarController.tabBar子视图。

因此,您的imgV添加到选项卡中。例如这里。

UIImage *img  = [UIImage imageNamed: @"home_selected.png"];
[imgV setImage:img];
[self.tabBarController.tabBar addSubview:imgV];
[self.tabBarController.tabBar bringSubviewToFront:imgV];

但要小心tabBarController.tabBarheight-size different tabBarControlller.view

因此,您应该设置框架的大小或坐标。

最新更新