给scrollVIew的panGestureRecognizer加一个target方法
[sc.panGestureRecognizer addTarget:self action:@selector(panAction:)];
使用一个contentOfSet记录下ScrollVIew的移动前的contentOfSet,然后:
- (void)panAction:(UIPanGestureRecognizer *)panGestureRecognizer {
CGPoint p = [panGestureRecognizer translationInView:self.sc];
NSLog(@"%ld",panGestureRecognizer.state);
NSLog(@"%@",NSStringFromCGPoint(p));
if(panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
self.contentOfSet = self.sc.contentOffset;
}
self.sc.contentOffset = CGPointMake( self.contentOfSet.x - p.x/4 , 0);
}
这样可以实现手指移动一屏幕,scrollVIew移动1/4屏幕
网友评论