iOS tableView滑动隐藏/显示tabbar

在需要滑动隐藏/显示的页面中:

@property(nonatomic,assign)CGFloat historyY;

#pragma mark Delegate

//设置滑动的判定范围
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
    if (historyY+20<targetContentOffset->y)
    {
        [self setTabBarHidden:YES];
    }
    else if(historyY-20>targetContentOffset->y)
    {
        
        [self setTabBarHidden:NO];
    }
    historyY=targetContentOffset->y;
}
//隐藏显示tabbar
- (void)setTabBarHidden:(BOOL)hidden
{
    UIView *tab = self.tabBarController.view;
    CGRect  tabRect=self.tabBarController.tabBar.frame;
    if ([tab.subviews count] < 2) {
        return;
    }
    
    UIView *view;
    if ([[tab.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]]) {
        view = [tab.subviews objectAtIndex:1];
    } else {
        view = [tab.subviews objectAtIndex:0];
    }
    
    if (hidden) {
        view.frame = tab.bounds;
        tabRect.origin.y=[[UIScreen mainScreen]bounds].size.height+self.tabBarController.tabBar.frame.size.height;
    } else {
        view.frame = CGRectMake(tab.bounds.origin.x, tab.bounds.origin.y, tab.bounds.size.width, tab.bounds.size.height);
        tabRect.origin.y=[[UIScreen mainScreen] bounds].size.height-self.tabBarController.tabBar.frame.size.height;
    }
    
    [UIView animateWithDuration:0.5f animations:^{
        self.tabBarController.tabBar.frame=tabRect;
    }completion:^(BOOL finished) {
        
    }];
    
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,930评论 25 708
  • 之前在做直播的时候,参照了映客App,发现其首页的效果还挺不错,在网上找了一下相关仿映客App代码和博客,大部分都...
    HK_Hank阅读 9,286评论 17 114
  • 暗恋是一朵食人花 明艳,要人命 跟所有女孩一样,我无可救药的喜欢上了一个人,而且,他是我初一的同学,陪伴走过了初中...
    三毛的撒哈拉阅读 223评论 0 0
  • 两只蜗牛 我是一只蜗牛 你是一只蜗牛 我们慢慢地慢慢地走着 我们慢慢地慢慢地接近了 放佛过了一个世纪那么长 我们终...
    意大利空姐亚亚阅读 1,168评论 0 2
  • 人的一生中都有最难忘的事,我最难忘的有很多,但有一件事令我终身难忘,也时时出现在我的脑海里! 那一天,天气很明媚,...
    曾嘉文阅读 368评论 0 2