Hiding Imageview

2019-08-17 19:03发布

问题:

I am adding uiimageview as a subview to tabbarcontroller.view. when i pushed to other viewcontroller tabbar gets hided but the image added to the tabbarcontroller is appearing. Please help me to remove the imageviewwhile pushing to other viewcontroller.

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

When pushing to other viewcontroller

    -(void)logoutBtnTap
    {
appDelegate.enterLogout=YES;
for(UIImageView *view in[self.view subviews])

{
    [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];

}

回答1:

beacuse hidesBottomBarWhenPushed=yes is mean your tabBarController hide tabbar not view.

Be a point of caution, you will need to add to imageView in tabBar not view.

maybe this method send to message tabBarController.tabBar subviews, when a operate push or pop object controller.

so, your imgV add to tabbar. here for example.

UIImage *img  = [UIImage imageNamed: @"home_selected.png"];
[imgV setImage:img];

[self.tabBarController.tabBar addSubview:imgV];
[self.tabBarController.tabBar bringSubviewToFront:imgV];

but carefully tabBarController.tabBar height-size different tabBarController.view

so, you frame should set size or coordinates.



回答2:

for(UIImageView *view in[self.view subviews])

{  
    for(UIImage *img in view.subviews){//remove photoes from the subview
     [img removeFromSuperview]; 
}
   [view removeFromSuperview];//remove uiimageview from the main view

}