2012-02-16 74 views
0

我想隱藏tabbar控制器和顯示uiimageview類似於它是如何在iphone的本機照片庫中完成的。我已經創建了該庫,但是我通過隱藏tabbar在下一個視圖中顯示圖像時遇到問題。我可以隱藏tabbar,但是當我嘗試添加uiimageview時,它不會佔用標籤欄佔用的空間。我希望我的uiimageview能夠延伸到屏幕底部。 我甚至想在該空白處添加一個按鈕,但我無法做到。完全顯示/隱藏tabbar控制器和使用空間

我的代碼隱藏標籤欄:

self.tabBarController.tabBar.hidden = YES; 

能有人幫幫我嗎?

感謝
潘卡

+0

你有任何解決方案嗎? – Johnykutty 2013-07-13 09:11:53

回答

0

試試這個

self.tabBarController.tabBar.hidden = YES; 

[imageView setFrame:CGRectMake(0,0,320,480)]; 
+0

我已經嘗試了多次,但它不起作用。 – pankaj 2012-02-16 10:58:04

0

只需使用以下兩種方法來隱藏或顯示的TabBar控制器。把這個方法放在委託類中,所以很容易從任何類中調用。

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

int height = 480; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.3]; 

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

}

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

    int height = 480; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.3]; 

    for(UIView *view in tabbarcontroller.view.subviews) { 

     if([view isKindOfClass:[UITabBar class]]) { 
      [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];    
     } 
     else { 
      [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)]; 
     } 
    }  

    [UIView commitAnimations]; 
} 
+0

考慮到不同的外形因素,您是否應該編碼高度?也許'int height = [[UIScreen mainScreen]範圍] .size.height;'' ? – Aardvark 2013-09-16 09:31:52

0

您需要設置tabBarController的看法財產的底部子視圖的框架,像這樣:

self.tabBarController.tabBar.hidden = YES; 
UIView* subview = (UIView*)[self.tabBarController.view.subviews objectAtIndex:0]; 
imageView.frame = subview.frame = self.window.bounds; 

這是我用過的以某種形式在一些產品中生產。您是否真的想要使用self.window.bounds取決於您的當前課程是否具有指向UIWindow的mainWindow實例的窗口屬性,您是否支持多個方向(窗口的邊界保持不變,無論當前的視圖控制器是旋轉的還是當前的UIInterfaceOrientation,窗戶不),如果你需要考慮狀態欄。如果考慮狀態欄(UIStatusBar),則將高度偏移20°。將子視圖投影到UIView允許您在此情況下使用點語法(靜態分析器無法分辨數組中的哪些對象)。

0

我一直在掙扎幾個小時。最後我找到了解決方案。只要按照下面的步驟:

  • 勾選上推箱隱藏底欄在你的孩子視圖控制器從故事板(你想隱藏標籤欄的一個)。

  • 將以下代碼添加到根視圖控制器中的viewWillAppear方法中:self.tabBarController?.tabBar.hidden = false

  • 在您推送的視圖控制器中的viewWillAppear方法中添加以下代碼:self.tabBarController?.tabBar.hidden = true

就這樣。它只是工作!

相關問題