UILongPressGestureRecognizer 仅调用第二次

发布于 2025-01-06 03:48:54 字数 1066 浏览 6 评论 0原文

这是我的问题,当我使用 UILongPressGestureRecognizer 时,它只在第二次起作用...我按 3 秒按钮,它不起作用,但第二次我按 3 秒按钮,它工作正常...一些想法?

-(IBAction)seleccionar1:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}

-(IBAction)seleccionar2:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}

- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer{
if(gestureRecognizer.view==boton1)
{
    [boton1 setTitle:@"Funciona 1" forState:UIControlStateNormal];
}
if(gestureRecognizer.view==boton2)
{
    [boton2 setTitle:@"Funciona 2" forState:UIControlStateNormal];
}}

感谢所有的朋友。

此致

It is my problem, when i used UILongPressGestureRecognizer, it only works in the second time... I push 3 seconds the button and it dont work, but the second time that i push 3 second the button it works fine... Some idea?

-(IBAction)seleccionar1:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}

-(IBAction)seleccionar2:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}

- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer{
if(gestureRecognizer.view==boton1)
{
    [boton1 setTitle:@"Funciona 1" forState:UIControlStateNormal];
}
if(gestureRecognizer.view==boton2)
{
    [boton2 setTitle:@"Funciona 2" forState:UIControlStateNormal];
}}

Thanks for all friends.

Best regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看透却不说透 2025-01-13 03:48:54

因为第一次手势没有添加到按钮,您将其添加到用户操作中..因此,将手势添加到之前的按钮,例如在 viewDidLoad 中。

because in the first time the gesture is not added to the button you add it on the user action .. so add the gestures to the buttons before that for example in the viewDidLoad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文