如何在 Swift 中将触摸事件发送到 nextResponder

How to send touch events to nextResponder in Swift

背景

我正在尝试让 UICollectionViewCell 的行为像一个按钮(即,在触摸时做一个动画暗淡)。我的想法是用 UIButton 填充单元格。然后按钮会处理被点击的视觉效果。但是然后我需要将触摸事件传递给父级(UICollectionViewCell),这样按钮就不会只消耗该事件。这样我就可以使用集合视图的 didSelectItemAtPath 来处理它。下面的问题是我试图弄清楚如何传递事件。

我的问题

我发现 this Objective-C answer 将触摸事件传递给:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  
    [super touchesBegan:touches withEvent:event];
    [self.nextResponder touchesBegan:touches withEvent:event]; 
}

但是,当我尝试将其转换为 Swift:

时卡住了
class MyButton: UIButton {

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        super.touchesBegan(touches, withEvent: event)
        self.nextResponder() // ???
    }
}

nextResponder 方法不接受任何参数,那么如何传递触摸事件?

我无法使用相关的 SO 问题 (here and here) 来帮助我解决这个问题。

nextResponder 方法 returns 一个可选的 UIResponder?,因此您可以简单地在返回的对象上调用 touchesBegan

self.nextResponder()?.touchesBegan(touches, withEvent: event)

更新:Swift 4.2

self.next?.touchesBegan(touches, with: event)

mmh02的回答更新为Swift4.2

next?.touchesBegan(touches, with: event)