问题
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