gpt4 book ai didi

iOS 检测用户触摸释放

转载 作者:可可西里 更新时间:2023-11-01 03:38:23 24 4
gpt4 key购买 nike

这可能已经张贴在这里某处,但我找不到它。我正在编写一个带有两个 UIView 的简单 iOS 应用程序。用户将首先按住屏幕的某个区域,然后松开触摸,然后快速触摸下方的第二个 View 。

第一个 UIView 有一个 UILongPressGestureRecognizer 附加到它并且工作正常。第二个 UIView 有一个 UITapGestureRecognizer 附加到它并且也可以正常工作。但是,我无法让这些手势识别器中的任何一个返回任何表明用户释放触摸的信息。

我试过这段代码无济于事:

- (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];
}

任何建议都会很好,特别是如果有人知道如何实现返回用户触摸设备状态的调用。我查看了开发人员文档,但一无所获。

最佳答案

修修补补几个小时后,我找到了一种可行的方法,但不确定这是否是最好的方法。结果我需要像下面的代码一样编写它。我没有调用我在 viewDidLoad() 方法中声明的特定 UIGestureRecognizer。

- (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 检测用户触摸释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7380389/

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