gpt4 book ai didi

ios - 如何检测 UISwipeGestureRecognizer 的结束?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:47:18 26 4
gpt4 key购买 nike

来自苹果文档

A swipe is a discrete gesture, and thus the associated action message is sent only once per gesture.

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event 

当我使用 UISwipeGestureRecognizer 时也不会被调用

如何检测用户何时抬起手指?

最佳答案

我想通了,实际上这很容易,而不是使用 UISwipeGestureRecognizer 来检测滑动,我自己使用事件处理来检测它

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
self.initialPosition = [touch locationInView:self.view];

}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint movingPoint = [touch locationInView:self.view];
CGFloat moveAmt = movingPoint.y - self.initialPosition.y;
if (moveAmt < -(minimum_detect_distance)) {
[self handleSwipeUp];
} else if (moveAmt > minimum_detect_distance) {
[self handleSwipeDown];
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[self reset];

}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
[self reset];
}

我没有对 UIGestureRecognizer 进行子类化,但只在所需的 View Controller 中进行了事件处理,因为在重置方法中,我正在重置属于 View Controller 的几个变量、计数器和计时器。

关于ios - 如何检测 UISwipeGestureRecognizer 的结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19896402/

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