如何隐藏特定选项卡索引的iOS选项卡栏,并在触摸屏幕时显示选项卡?
我试图隐藏特定视图的选项卡栏,并在触摸屏幕时显示出来。我希望它具有与youtube类似的效果,例如,当视频播放时,播放器控件被隐藏,触摸屏幕时,控件再次显示。您是否尝试过直接隐藏选项卡栏? 在视图控制器中,如果不希望有选项卡栏,请添加如何隐藏特定选项卡索引的iOS选项卡栏,并在触摸屏幕时显示选项卡?,ios,uitabbarcontroller,Ios,Uitabbarcontroller,我试图隐藏特定视图的选项卡栏,并在触摸屏幕时显示出来。我希望它具有与youtube类似的效果,例如,当视频播放时,播放器控件被隐藏,触摸屏幕时,控件再次显示。您是否尝试过直接隐藏选项卡栏? 在视图控制器中,如果不希望有选项卡栏,请添加tabBar.hidden=YES到视图将出现:或视图显示:到具有内部事件触发器的涂改的反转tabBar.hidden=NO 我个人并没有对选项卡栏进行过此操作,但这适用于其他视图,所以这是我首先尝试的方法。您是否尝试过直接隐藏选项卡栏? 在视图控制器中,如果不希望
tabBar.hidden=YES代码>到视图将出现:
或视图显示:
到具有内部事件触发器的涂改的反转tabBar.hidden=NO代码>
我个人并没有对选项卡栏进行过此操作,但这适用于其他视图,所以这是我首先尝试的方法。您是否尝试过直接隐藏选项卡栏?
在视图控制器中,如果不希望有选项卡栏,请添加tabBar.hidden=YES代码>到视图将出现:
或视图显示:
到具有内部事件触发器的涂改的反转tabBar.hidden=NO代码>
我个人没有对选项卡栏执行此操作,但这适用于其他视图,因此我将首先尝试这种方式。您可以使用以下代码显示和隐藏选项卡栏:
@implementation UITabBarController (Extras)
-(void)showTabBar:(BOOL)show {
UITabBar* tabBar = self.tabBar;
if (show != tabBar.hidden)
return;
UIView* subview = [self.view.subviews objectAtIndex:0];
CGRect frame = subview.frame;
frame.size.height += tabBar.frame.size.height * (show ? -1 : 1);
subview.frame = frame;
tabBar.hidden = !show;
}
这段代码很有效,最近苹果在一个应用程序中接受了它,而且(作为一个类别),我发现它比其他解决方案更易于使用
如果要隐藏选项卡栏,只需调用:
[self.tabBarController showTabBar:NO];
同样,要再次显示该消息,请使用YES
作为参数调用此消息
注意:不知何故,我忘记了我在过去的某个时候已经查找过这段代码,现在我不确定最初是谁回答的。索拉布。
Saurabh提供的代码遍历所有视图,查找isKindOfClass:[UITabBar class]
,而我只抓取第一个子视图,它在面对更新时可能很脆弱。您可以使用此代码显示和隐藏选项卡栏:
@implementation UITabBarController (Extras)
-(void)showTabBar:(BOOL)show {
UITabBar* tabBar = self.tabBar;
if (show != tabBar.hidden)
return;
UIView* subview = [self.view.subviews objectAtIndex:0];
CGRect frame = subview.frame;
frame.size.height += tabBar.frame.size.height * (show ? -1 : 1);
subview.frame = frame;
tabBar.hidden = !show;
}
Try This Code
- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
float fHeight = screenRect.size.height;
if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
{
fHeight = screenRect.size.width;
}
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
view.backgroundColor = [UIColor blackColor];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
float fHeight = screenRect.size.height - 49.0;
if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
{
fHeight = screenRect.size.width - 49.0;
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
}
}
[UIView commitAnimations];
}
这段代码很有效,最近苹果在一个应用程序中接受了它,而且(作为一个类别),我发现它比其他解决方案更易于使用
如果要隐藏选项卡栏,只需调用:
[self.tabBarController showTabBar:NO];
同样,要再次显示该消息,请使用YES
作为参数调用此消息
注意:不知何故,我忘记了我在过去的某个时候已经查找过这段代码,现在我不确定最初是谁回答的。索拉布。
Saurabh提供的代码遍历所有视图,查找isKindOfClass:[UITabBar class]
,而我只获取第一个子视图——在更新时它可能很脆弱。尝试以下方法:
Try This Code
- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
float fHeight = screenRect.size.height;
if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
{
fHeight = screenRect.size.width;
}
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
view.backgroundColor = [UIColor blackColor];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
float fHeight = screenRect.size.height - 49.0;
if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
{
fHeight = screenRect.size.width - 49.0;
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
}
}
[UIView commitAnimations];
}
self.tabBarController.tabbar.hidden = YES;
将其放在viewDidLoad中。尝试以下操作:
self.tabBarController.tabbar.hidden = YES;
把它放在viewDidLoad中。确实隐藏了选项卡栏,但我现在在屏幕底部得到了一个49像素高的空白。视图不会自动调整大小以填充视图,而尝试手动更改视图框则不会产生任何效果。@AndrewS检查这个问题,这是针对推式视图的;我想在选项卡栏中的一个选项卡中使用它。我最终使用了iOS 7中的代码。iOS 6需要框架破解。确实隐藏了标签栏,但我现在在屏幕底部有一个49像素高的空白。视图不会自动调整大小以填充视图,而尝试手动更改视图框则不会产生任何效果。@AndrewS检查这个问题,这是针对推式视图的;我想在选项卡栏中的一个选项卡中使用它。我最终使用了iOS 7中的代码。iOS 6需要框架破解。请看我对类似问题的回答:最佳,请看我对类似问题的回答:最佳,