有了UIPanGestureRecognizer,有没有一种方法只能像许多像素被淘汰之后那么频繁?

现在我的UIPanGestureRecognizer可以识别每个单独的平移,这是非常好的必要条件,但是由于我用滑动手势来增加和减less一个variables的值,所以我只想每隔一段时间就采取行动。 如果我每次检测到增加1,那么这个值就会变得太快。

有没有办法做像这样的每10个像素的像这样或类似的东西?

你正在寻找translationInView: :,它告诉你锅已经进步了多less,并可以testing你的最小距离。 这个解决scheme并不包括在一个方向上来回走动的情况,其数量等于最小距离,但如果这对您的情况很重要,那么添加并不难。

 #define kMinimumPanDistance 100.0f UIPanGestureRecognizer *recognizer; CGPoint lastRecognizedInterval; - (void)viewDidLoad { [super viewDidLoad]; recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didRecognizePan:)]; [self.view addGestureRecognizer:recognizer]; } - (void)didRecognizePan:(UIPanGestureRecognizer*)sender { CGPoint thisInterval = [recognizer translationInView:self.view]; if (abs(lastRecognizedInterval.x - thisInterval.x) > kMinimumPanDistance || abs(lastRecognizedInterval.y - thisInterval.y) > kMinimumPanDistance) { lastRecognizedInterval = thisInterval; // you would add your method call here } }