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)];

}

}];

}

}];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.NSTimer //暂停if ([timer isValid]) {[timer setFireDate:[N...
    俊月阅读 1,480评论 0 0
  • 当页面使用 UITabBarController + UINavigationController 框架的...
    墨隐于非阅读 3,078评论 0 8
  • ViewsBecause view objects are the main way your applicati...
    梁光飞阅读 747评论 0 0
  • 麻城白果镇,望花山总支,闹市河水岩,政策合并村。 人口三千多,小二型水库,黑石咀水库,灌溉农秧田。 辖云雾山寨,左...
    冲天农锄草阅读 1,475评论 14 57
  • “总是向你索取,却不曾说谢谢你/ 直到长大以后,才懂得你不容易/” … “时光时光慢些吧,不要再让你变老了/ 我愿...
    LeoRex阅读 525评论 0 1

友情链接更多精彩内容