我已经设置了一个UISwipeGestureRecognizer
:
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:delegate action:@selector(handleSwipeGesture:)];
swipe.direction = UISwipeGestureRecognizerDirectionUp;
[self addGestureRecognizer:swipe];
[swipe release];
滑动使玩家沿着滑动的方向移动。不过,我需要玩家继续移动,直到滑动的手指离开屏幕。我尝试过使用 TouchesEnded: 方法,但它要求首先进行非滑动触摸。我怎样才能获得做出滑动手势的触摸?如何检测触摸何时离开屏幕?
我知道您已经对这个问题的答案感到满意,但我想我可能会建议使用 UIPanGestureRecognizer 而不是滑动手势。
使用平移手势识别器,消息会重复发送到选择器,直到用户停止拖动手指,此时再次调用选择器,传递一个gesture.state
of 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.
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)