检测UISwipeGesture [识别器]后手指抬起的时间

Ars*_*yev 5 iphone objective-c uikit uigesturerecognizer

我已经建立了一个UISwipeGestureRecognizer:

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:delegate action:@selector(handleSwipeGesture:)];
swipe.direction = UISwipeGestureRecognizerDirectionUp;
[self addGestureRecognizer:swipe];
[swipe release];
Run Code Online (Sandbox Code Playgroud)

滑动使玩家向滑动方向移动.但是,我需要玩家继续移动,直到滑动的手指从屏幕上抬起.我尝试过使用touchesEnded:方法,但它要求首先进行非滑动触摸.如何获得滑动手势的触摸?如何检测触摸屏从屏幕上抬起的时间?

dal*_*ook 6

我知道你已经对这个问题的答案感到满意,但我想我可能会建议使用UIPanGestureRecognizer而不是滑动手势.

与平移姿势识别器,直到用户停止拖动他们的手指,在该点所述选择器被称为一个更多的时间,传递的消息被发送到选择器反复gesture.stateUIGestureRecognizerStateEnded.例:

- (void)panGesture:(UIPanGestureRecognizer *)gesture {
    if (gesture.state == UIGestureRecognizerStateEnded) {
        CGPoint translation = [gesture translationInView:self.view];
        //This contains the total translation of the touch from when it 
        //first recognized the gesture until now.
        //
        //e.g (5, -100) would mean the touch dragged to the right 5 points, 
        //and up 100 points.
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 在Swift语言下,这会改为`if(gesture.state == UIGestureRecognizerState.Ended)`或者只是`if(gesture.state == .Ended)`. (3认同)

Ars*_*yev 1

翻阅Apple的文档后,我发现了UIGestureRecognizer的这个属性:

@property(nonatomic) BOOL cancelsTouchesInView
Run Code Online (Sandbox Code Playgroud)

将其设置为NO允许接收者的视图处理属于手势识别器接收的多点触摸序列一部分的所有触摸。