How to add UIViewController as subview , to be visible above tabbar?

回眸只為那壹抹淺笑 提交于 2019-12-25 04:37:06

问题


I want to add the view of a UIViewController as a subview. But self.view is having a UITabBarController. I want to display the subview above tabbar. So that tab bar hides behind subview. Please suggest some idea.


回答1:


Try this, if you want to hide/show the UITabBarController of view:

For hide the tabbar:

 - (void)hideTabBar:(UITabBarController *) tabbarcontroller
 {
     for(UIView *view in tabbarcontroller.view.subviews)
     {
        if([view isKindOfClass:[UITabBar class]])
       {
           [view setFrame:CGRectMake(view.frame.origin.x, (isiPhone5?568:480), view.frame.size.width, view.frame.size.height)];
        }
        else
        {
           [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, isiPhone5?568: 480)];
        }
     }
  }

for show Tabbar:

   - (void)showTabBar:(UITabBarController *) tabbarcontroller
     {

         for(UIView *view in tabbarcontroller.view.subviews)
         {
            if([view isKindOfClass:[UITabBar class]])
            {
               [view setFrame:CGRectMake(view.frame.origin.x,  (isiPhone5?519:431), view.frame.size.width, view.frame.size.height)];
            }
            else
            {
               [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width,  isiPhone5?519:431)];
            }
         }
      }

may be it will help.




回答2:


Where you alloc and initialize TabBar, write this line

objectOfTabbar.hidden=YES; 

Then give the frame of your subview same as of TabBarController. This way your tabbar will be hidden and view will be shown .



来源:https://stackoverflow.com/questions/19999532/how-to-add-uiviewcontroller-as-subview-to-be-visible-above-tabbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!