小知识点好东西iOS Developer

如何实现手指滑动一屏,scrollVIew滚动半屏或更小

2017-04-14  本文已影响347人  老骚鹅

给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屏幕

上一篇下一篇

猜你喜欢

热点阅读