UIScrollView上下拉隐藏显示底部条

2017-10-09 14_42_45.gif

只需实现UIScrollViewDelegate的scrollViewDidScroll:方法,在里面获取手势的速度并作相应处理即可。另外一般隐藏要灵敏些。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];
    NSTimeInterval timeDiff = currentTime - _lastOffsetCapture;
    if(timeDiff > 0.1) {
        CGFloat velocity = [scrollView.panGestureRecognizer velocityInView:scrollView].y;
        velocity = velocity/1000.0;
        NSLog(@"===============:%f",velocity);
        if (velocity < 0) {
            //向下滑
            [UIView animateWithDuration:0.25 animations:^{
                _bottomView.frame = CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, 49);
            } completion:^(BOOL finished) {
                
            }];
        } else if (velocity > 0.5) {
            //向上滑
            [UIView animateWithDuration:0.25 animations:^{
                _bottomView.frame = CGRectMake(0, self.view.bounds.size.height-49, self.view.bounds.size.width, 49);
            } completion:^(BOOL finished) {
                
            }];
        }
    }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容