method
触发基于Pan gesture
价值的最佳方式是什么?
我想method
在我pan location x
介于 500 到 600 之间时触发。人们通常如何处理这个?
method
触发基于Pan gesture
价值的最佳方式是什么?
我想method
在我pan location x
介于 500 到 600 之间时触发。人们通常如何处理这个?
You need to override gestureRecognizerShouldBegin. Then you can detect translation.x and see where the values fall between.
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)panGestureRecognizer {
CGPoint translation = [panGestureRecognizer translationInView:self.view];
if (translation.x > 500 && translation.x < 600)
[self callCustom];
return true;
}
- (void) callCustom {
//do what you need to do
}
我假设您有一个处理平移手势的方法。使该方法看起来像这样。
- (void)handlePan:(UIPanGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateChanged) {
CGPoint movement = [recognizer translationInView:self.view];
if (movement.x >= 500 && movement.x <= 600) {
[self methodToCall];
}
}
}