2011-09-30 80 views

回答

3

您是否試圖直接隱藏標籤欄? 在視圖控制器,你要沒有一個標籤欄,添加tabBar.hidden = YES;viewWillAppear:viewDidAppear:扭轉這種具有觸摸釋放,內部事件觸發tabBar.hidden = NO;

我沒有親自與標籤欄做到了這一點,但是這與其他觀點一起工作,所以這是我首先嚐試的方式。

+0

確實隱藏標籤欄,但我得到一個49像素高的白色空間在底部現在的屏幕。該視圖不會自動調整大小以填充它,並嘗試手動更改視圖框架不做任何事情。 – AndrewS

+1

@AndrewS檢查出這個問題http://stackoverflow.com/questions/3807255/how-do-i-hid-the-uitabbarview-when-loading-some-view –

+0

這是爲推視圖;我想要它在標籤欄中的一個選項卡。我在[如何隱藏uitabbarcontroller]中使用代碼結束了(http://stackoverflow.com/questions/5272290) – AndrewS

6

您可以使用此代碼來顯示和隱藏標籤欄:

@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; 
} 

此代碼的工作,最近被蘋果應用程序接受,(作爲一個類別),我發現更容易比其他使用解決方案。

當你想隱藏的TabBar,只要致電:

[self.tabBarController showTabBar:NO]; 

同樣,再次顯示它,把這個消息YES作爲參數。

注意:不知何故,我忘記了我過去曾經查過這段代碼,現在我不確定誰最初回答了這個問題。 Saurabh answered a similar question。 由Saurabh提供的代碼遍歷所有的視圖尋找isKindOfClass:[UITabBar class],而我只是抓住第一個子視圖 - 這可能是在更新面臨脆弱。

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

試試這個:

self.tabBarController.tabbar.hidden = YES; 

把它放在viewDidLoad中。