美文网首页UITableView
UIScrollview 滑动到边界的时候整个视图连带滑动效果

UIScrollview 滑动到边界的时候整个视图连带滑动效果

作者: T_aa | 来源:发表于2019-11-06 20:41 被阅读0次

    效果:


    2019-11-07 09-24-42.2019-11-07 09_25_03.gif

    代码:

    
    -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
        if(self.tableView.contentOffset.y <= 0){
            scrollView.contentOffset = CGPointMake(0, 0);
            [self panEvent:scrollView.panGestureRecognizer];
        }
    }
    
    -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
        [self panEvent:scrollView.panGestureRecognizer];
    }
    
    -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
        [self panEvent:scrollView.panGestureRecognizer];
    }
    
    - (void)panEvent:(UIPanGestureRecognizer *)sender{
    
        static CGFloat beginOffset = 0;
        
        if(sender.state == UIGestureRecognizerStateChanged){
                
            CGPoint offset = [sender translationInView:self.view];
            
            if(offset.y > 0){
                self.tableView.transform = CGAffineTransformMakeTranslation(0, offset.y-beginOffset);
            }
        }
        
        if(sender.state == UIGestureRecognizerStateEnded){
            beginOffset = 0;
            [UIView animateWithDuration:0.2 animations:^{
                self.tableView.transform = CGAffineTransformIdentity;
            }];
        }
        
        if(sender.state == UIGestureRecognizerStateBegan){
            beginOffset = self.tableView.contentOffset.y;
        }
    }
    
    

    相关文章

      网友评论

        本文标题:UIScrollview 滑动到边界的时候整个视图连带滑动效果

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