gpt4 book ai didi

objective-c - 检测平移手势结束

转载 作者:IT老高 更新时间:2023-10-28 11:37:24 25 4
gpt4 key购买 nike

我有一个 View ,我将 UIPanGestureRecogniser 应用于该 View :

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAnim:)];
[sliderView addGestureRecognizer:panGesture];
[panGesture release];

我可以很好地检测和处理手势。但是,我希望在手势结束后启动另一个方法。

我知道有两种方法可以进行这种检测。 touchesEndedtouchesCancelled 但是,我发现 touchesCancelled 一旦触摸变成手势即被调用,即我移动手指足以保证手势调用和 touchesEnded 很少(如果有的话)被调用。

我希望能够向左/向右平移,然后在手势结束时启动另一个函数调用。我该怎么做?

最佳答案

可以通过使用 UIGestureRecognizerStateEnded 检查其状态来检测平移手势结束事件。

检查下面的代码。

-(void) panAnim:(UIPanGestureRecognizer*) gestureRecognizer
{
if(gestureRecognizer.state == UIGestureRecognizerStateEnded)
{
//All fingers are lifted.
}
}

来自 Apple 文档

A panning gesture is continuous. Itbegins (UIGestureRecognizerStateBegan)when the minimum number of fingersallowed (minimumNumberOfTouches) hasmoved enough to be considered a pan.It changes(UIGestureRecognizerStateChanged) whena finger moves while at least theminimum number of fingers are presseddown. It ends(UIGestureRecognizerStateEnded) whenall fingers are lifted.

Read more about UIPanGestureRecognizer

关于objective-c - 检测平移手势结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6467638/

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