UITabBarViewController 的底部 tabBar 隱藏

iOS pushViewController 時候隱藏 TabBar 的可以用

@interfaceUIViewController (UINavigationControllerItem)

@property(nonatomic,readonly,strong)UINavigationItem*navigationItem;// Created on-demand so that a view controller may customize its navigation appearance.

@property(nonatomic)BOOL hidesBottomBarWhenPushed __TVOS_PROHIBITED;// If YES, then when this view controller is pushed into a controller hierarchy with a bottom bar (like a tab bar), the bottom bar will slide out. Default is NO.

這是系統提供的 UINavigationViewController 的方法。你只需要在被push 的 UIViewcontroller 的初始化方法中添加這個屬性就行。

self.hidesBottomBarWhenPushed = YES;

這樣有2個問題

1. 是做 pushViewController transition 過渡的時候,動畫中會看到 tabBar 被移出去,尤其是被push 的viewController 的背景色反差很大的時候,體驗很差。
2. presentViewController 的時候無法使用這個方法。


解決方法:

自己控制 UITabBarViewController 的 bottom tabBar。setFrame的方法控制。

- (void)hideTabBar {
[self setTabBarHidden:YES];
}

- (void)showTabBar {
[self setTabBarHidden:NO];
|}

- (void) setTabBarHidden:(BOOL)hidden {

CGRect screenRect = [[UIScreen mainScreen] bounds];

floatfHeight = screenRect.size.height;

if(UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))

fHeight = screenRect.size.width;

if(!hidden) fHeight -=self.tabBar.frame.size.height;

[UIViewanimateWithDuration:0.25 animations: ^{

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

if([view isKindOfClass:[UITabBar class]]) {

[view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];

}else{

if(hidden) [viewsetFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];

}

}

}completion:^(BOOLfinished) {

if(!hidden) {

[UIViewanimateWithDuration:0.25animations: ^{

for(UIView*viewinself.view.subviews) {

if(![viewisKindOfClass:[UITabBarclass]])

[viewsetFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];

}

}];

}

}];

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 1.NSTimer //暫停if ([timer isValid]) {[timer setFireDate:[N...
    俊月閱讀 1,373評論 0 0
  • 當頁面使用 UITabBarController + UINavigationController 框架的...
    墨隱于非閱讀 3,008評論 0 8
  • ViewsBecause view objects are the main way your applicati...
    梁光飛閱讀 641評論 0 0
  • 麻城白果鎮,望花山總支,鬧市河水巖,政策合并村。 人口三千多,小二型水庫,黑石咀水庫,灌溉農秧田。 轄云霧山寨,左...
    沖天農鋤草閱讀 1,427評論 14 57
  • “總是向你索取,卻不曾說謝謝你/ 直到長大以后,才懂得你不容易/” … “時光時光慢些吧,不要再讓你變老了/ 我愿...
    LeoRex閱讀 492評論 0 1