UIPanGestureRecognizer:在滑动结束时检测触摸位置

UIPanGestureRecognizer: detect touch location at end of swipe

我在touchesEnded方法中调用了一个方法叫addProjectile。 addProjectile 接收 touchesEnded 方法接收的 NSSet 触摸。为简单起见,我只将相关代码发布到我的问题中。所以,要明确一点:

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self addProjectile:touches]; }
-(void) addProjectile:(NSSet *)touches {//do stuff }

我想在名为 swipeRight 的 UIPanGestureRecognizer 方法末尾调用 addProjectile 并发送正确的 NSSet 触摸。

-(void)swipedRight:(UIPanGestureRecognizer *)recognizer {
    CGPoint panned=[recognizer translationInView:self.view];
    if(panned.x>50){//do stuff }
    else {
    NSSet *touches; <-- this is what I need to get
    [self addProjectile:touches];

所以我的问题是如何在 swipedRight: 结束时获得正确的触摸 NSSet(这将是用户拿起 his/her 手指的位置)以正确执行 addProjectile 方法。

看看UIGestureRecognizerState。这就是你需要的。

示例代码(这里假设,您只需要用户完成平移即抬起手指时的触摸点):

-(void)swipedRight:(UIPanGestureRecognizer *)panGesture {

    if ([panGesture state] == UIGestureRecognizerStateEnded) {

        //User touch has ended

        CGPoint touchUpPoint = [panGesture translationInView:self.view]; // or `locationInView:`

        NSLog(@"__TOUCH_END_POINT__ = %@", NSStringFromCGPoint(touchUpPoint));
    }
}