我已经设置了UISwipeGestureRecognizer
:
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:delegate action:@selector(handleSwipeGesture:)];
swipe.direction = UISwipeGestureRecognizerDirectionUp;
[self addGestureRecognizer:swipe];
[swipe release];
滑动可使玩家向滑动方向移动。但是,我需要播放器继续移动,直到将进行滑动的手指从屏幕上抬起为止。我尝试使用touchesEnded:方法,但它要求首先进行非滑动触摸。如何获得做出滑动手势的触摸?我如何检测该触摸何时脱离屏幕?
最佳答案
我知道您已经对这个问题的答案感到满意,但是我想我建议您使用UIPanGestureRecognizer而不是滑动手势。
使用摇动手势识别器,该消息会重复发送到选择器,直到用户停止拖动手指为止,此时,选择器会再调用一次,传递gesture.state
的UIGestureRecognizerStateEnded
。例子:
- (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.
}
}
关于iphone - 在UISwipeGesture后检测手指何时抬起[Recognizer],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3427280/