gpt4 book ai didi

ios - 如何检测同时手势的结束? (iOS)

转载 作者:可可西里 更新时间:2023-11-01 17:11:00 25 4
gpt4 key购买 nike

在我的应用程序中,我同时使用 UIPinchGestureRecognizer、UIRotationGestureRecognizer 和 UIPanGestureRecognizer 来缩放、旋转和移动图像。

方法 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: 总是返回 YES 并且图像处理效果很好,但是......我如何检测所有同时手势的结束,以便我可以重置图像?

最佳答案

一个简单的解决方案怎么样,比如计算当前正在处理的手势,并在所有手势结束时采取行动?

.h文件:

int handledGesturesCount;

.m文件:

- (id)init {
(...)
handledGesturesCount = 0;
}

// gesture handlers - the code for -pinch: repeats for -pan: and -rotate:
- (void)pinch:(UIPinchGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
handledGesturesCount += 1;
} else if (recognizer.state == UIGestureRecognizerStateEnded ||
recognizer.state == UIGestureRecognizerStateCancelled ||
recognizer.state == UIGestureRecognizerStateFailed)
{
handledGesturesCount -= 1;
if (handledGesturesCount == 0) {
[self resetImage];
}
}
}

- (void)pan:(UIPanGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
handledGesturesCount += 1;
} else if (recognizer.state == UIGestureRecognizerStateEnded ||
recognizer.state == UIGestureRecognizerStateCancelled ||
recognizer.state == UIGestureRecognizerStateFailed)
{
handledGesturesCount -= 1;
if (handledGesturesCount == 0) {
[self resetImage];
}
}
}

- (void)rotate:(UIRotationGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
handledGesturesCount += 1;
} else if (recognizer.state == UIGestureRecognizerStateEnded ||
recognizer.state == UIGestureRecognizerStateCancelled ||
recognizer.state == UIGestureRecognizerStateFailed)
{
handledGesturesCount -= 1;
if (handledGesturesCount == 0) {
[self resetImage];
}
}
}

关于ios - 如何检测同时手势的结束? (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7806866/

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