UIScrollview 滑动到边界的时候整个视图连带滑动效果
2019-11-06 本文已影响0人
T_aa
效果:
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;
}
}