【问题标题】:Override UIGestureRecognizer touchesBegan覆盖 UIGestureRecognizer touchesBegan
【发布时间】:2014-10-22 11:13:19
【问题描述】:

我有 1 个主视图和 1 个子视图

主视图 > 子视图

我认为主视图正在“窃取”来自 SubView 的事件。

例如,当我点击 SubView 时,只有 Main View GestureRecognizer 会触发。

这是我的自定义 GestureRecognizer(拦截每个触摸事件):

import UIKit
import UIKit.UIGestureRecognizerSubclass

class MainGestureRecognizer: UIGestureRecognizer {
    
    override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
        super.touchesBegan(touches, withEvent: event);
        //nextResponder() ??
        
        state = UIGestureRecognizerState.Began;
    }
 
    override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) {
        super.touchesMoved(touches, withEvent: event);
        //nextResponder() ??
        
        state = UIGestureRecognizerState.Changed;
    }
 
    override func touchesEnded(touches: NSSet!, withEvent event: UIEvent!) {
        super.touchesEnded(touches, withEvent: event);
        //nextResponder() ??
        
        state = UIGestureRecognizerState.Ended;
    }
 
    override func touchesCancelled(touches: NSSet!, withEvent event: UIEvent!) {
        super.touchesCancelled(touches, withEvent: event);
        //nextResponder() ??
        
        state = UIGestureRecognizerState.Cancelled;
    }
}

也许我应该使用 nextResponder,但我只找到了 Obj-C 代码,例如:

[self.nextResponder touchesBegan:touches withEvent:event];

What's the trick to pass an event to the next responder in the responder chain?

Is there a way to pass touches through on the iPhone?

所以问题是,我应该怎么做才能让第二个事件(SubView 事件)也触发?

在 Swift 中有没有类似 nextResponder 的函数?

【问题讨论】:

    标签: swift overriding touch-event


    【解决方案1】:

    噢!这是 nextResponder 的 Swift 代码:

    https://stackoverflow.com/a/26510277/4135158

    【讨论】:

    • 您介意发布一些代码吗?我无法弄清楚该链接如何解决您(和我)的问题。
    猜你喜欢
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 2018-03-30
    • 1970-01-01
    相关资源
    最近更新 更多