iOS检测用户触摸释放 [英] iOS Detect User Touch Release

查看:45
本文介绍了iOS检测用户触摸释放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能已经发布在这里的某个地方,但我找不到它.我正在编写一个带有两个UIView的简单iOS应用.用户将首先按住屏幕的某个区域,然后释放其触摸,然后快速触摸下面的第二个视图.

This may have been posted here somewhere but I can't find it. I am writing a simple iOS app with two UIViews. The user will first press and hold a certain area of the screen then release their touch on it then quickly touching a second view below.

第一个UIView带有一个UILongPressGestureRecognizer并可以正常工作.第二个UIView带有一个UITapGestureRecognizer并可以正常工作.但是,我无法使这些手势识别器中的任何一个返回表示用户释放其触摸的任何内容.

The first UIView has a UILongPressGestureRecognizer attached to it and works fine. The second UIView has a UITapGestureRecognizer attached to it and also works fine. I cannot however, get either of these gesture recognizers to return anything that states that the user released their touch.

我已经尝试了以下代码:

I have tried this code to no avail:

- (void)holdAction:(UILongPressGestureRecognizer *)holdRecognizer
{
    if (UIGestureRecognizerStateRecognized) {
        holdLabel.text = @"Holding Correctly. Release Touch when ready.";
        holdView.backgroundColor = [UIColor greenColor];
    } else if (UIGestureRecognizerStateCancelled){
        holdLabel.text = @"Ended";
        holdView.backgroundColor = [UIColor redColor];
}

任何建议都是很好的选择,尤其是如果有人知道如何实现返回用户触摸设备状态的呼叫时,尤其如此.我查看了开发人员文档,结果空白.

Any suggestions would be great and especially if someone knows how to implement a call that returns the state of a user touching the device. I've looked over the developer docs and have come up empty.

推荐答案

修补了几个小时后,我发现了一种可行的方法,不确定它是否是最佳方法.原来我需要像下面的代码一样编写它.我没有调用在viewDidLoad()方法中声明的特定UIGestureRecognizer.

After tinkering for a couple hours, I found a way that is working, not sure if its the best way to do it. Turns out I need to be writing it like the code below. I wasn't calling the specific UIGestureRecognizer I was declaring in the viewDidLoad() method.

- (void)holdAction:(UILongPressGestureRecognizer *)holdRecognizer
{
    if (holdRecognizer.state == UIGestureRecognizerStateBegan) {
        holdLabel.text = @"Holding Correctly. Release when ready.";
        holdView.backgroundColor = [UIColor greenColor];
    } else if (holdRecognizer.state == UIGestureRecognizerStateEnded)
    {
        holdLabel.text = @"You let go!";
        holdView.backgroundColor = [UIColor redColor];
    }
}

这篇关于iOS检测用户触摸释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆