滚动视图滚动时如何调用uipangesture?

时间:2012-11-14 09:10:11

标签: ios uiscrollview uipangesturerecognizer

我想通过UIScrollView更改UIPanGestureRecognizer'中心。滚动视图垂直滚动。我横向平移它。问题是当scrollview还在滚动时如何检测UIPanGestureRecognizer ??? 提前谢谢!

1 个答案:

答案 0 :(得分:0)

修改:您可以自定义UIScrollView并覆盖此方法:

#import "MyScrollView.h"

@implementation MyScrollView

- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
    return YES;
}

@end

self.panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
self.panGesture.delegate = self;
[self.view addGestureRecognizer:self.panGesture];

- (void)handlePan:(UIGestureRecognizer *)gestureRecognizer
{
    if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
        CGPoint offset = self.scrollView.contentOffset;
        offset.y = self.scrollView.contentSize.height/2;
        self.scrollView.contentOffset = offset;
    }
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return YES;
}