gpt4 book ai didi

iphone - UIView 中的两个 UITapGestureRecognizer

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

我想添加到我的 UIViewController :

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:tapGesture];
[tapGesture release];

UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture2:)];
tapGesture2.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tapGesture2];
[tapGesture2 release];

问题是如果用户点击两次这两个方法被调用,我希望如果用户双击只调用第一个(handleTapGesture),如果他点击一次它只会调用第二个( handleTapGesture2)

最佳答案

用这个..

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture)];
tapGesture.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:tapGesture];
[tapGesture release];

UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture2)];
tapGesture2.numberOfTapsRequired = 1;

[tapGesture2 requireGestureRecognizerToFail: tapGesture];

[self.view addGestureRecognizer:tapGesture2];
[tapGesture2 release];

关于iphone - UIView 中的两个 UITapGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10188834/

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