1

我想UIScrollView通过UIPanGestureRecognizer. 滚动视图垂直滚动。我水平平移它。问题是如何检测UIPanGestureRecognizer滚动视图何时仍在滚动???先感谢您!

4

1 回答 1

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;
}
于 2012-11-14T16:01:21.353 回答