美文网首页
UIScrollView上下拉隐藏显示底部条

UIScrollView上下拉隐藏显示底部条

作者: GTReload | 来源:发表于2017-10-09 14:47 被阅读0次
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) {
                
            }];
        }
    }
}

相关文章

网友评论

      本文标题:UIScrollView上下拉隐藏显示底部条

      本文链接:https://www.haomeiwen.com/subject/ryqpyxtx.html