效果:
代码:
-(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;
}
}