UIScrollView上下拉隐藏显示底部条

96
GTReload
2017.10.09 14:47* 字数 41
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) {
                
            }];
        }
    }
}

日记本
Web note ad 1