【问题标题】:TouchesBegan overriding touchUpInside actionsTouchesBegan 覆盖 touchUpInside 动作
【发布时间】:2023-03-07 08:21:01
【问题描述】:

我已经实现了一个自定义 UIButton,为了让我处理 LongPress 事件(不使用手势识别器),我不得不在我的课堂上使用 touchesBegan:touchesEnded:。问题是现在常规按钮事件不起作用。我想知道这是什么原因造成的,我该如何避免呢?

基于触摸的事件正在运行,但我之前对 touchUpInside: 执行的操作不再起作用。

谢谢

【问题讨论】:

    标签: iphone ios5 uibutton touchesbegan


    【解决方案1】:

    不要使用touchesBegan: 进行长按,使用这个手势识别器!

    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]     initWithTarget:self action:@selector(longTap:)];
    [view addGestureRecognizer:longPressGesture];
    [longPressGesture release];
    
    -(void) longTap:(UILongPressGestureRecognizer *)gestureRecognizer{
        NSLog(@"gestureRecognizer= %@",gestureRecognizer);
        if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
            NSLog(@"longTap began");
        } 
    }
    

    【讨论】:

    • 我想避免这种情况。手势识别器限制了我的 iOS 目标受众。我想远离它。
    • 什么意思?手势识别器从 iOS3.2 开始就已经存在了!没有人再使用 2.0.. 世界上几乎每个人都至少在使用 iOS 4.0!
    • 一些我无法通过的要求:P
    • 附带说明,长按识别器会继续触发吗?只要按下按钮,我就需要更新滑块。 StateBegan 只会触发一次。只有当我在按住按钮的同时移动手指时,StateChange 才会触发。所以我可能不得不使用计时器触发事件​​
    • 只要您一直按住,长按识别器只会触发一次。如果你需要做那个滑块的事情而不是是的,你可能需要 touchesbegan 和 touchesended。尽管如此,UIButtons 和 touchesbegan 和 touchesended 应该同时工作..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 2012-08-07
    • 2018-07-07
    相关资源
    最近更新 更多