gpt4 book ai didi

iphone - 在 UISwipeGesture[Recognizer] 之后检测手指何时抬起

转载 作者:太空狗 更新时间:2023-10-30 03:50:58 25 4
gpt4 key购买 nike

我已经设置了一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com