【发布时间】:2019-05-10 19:52:56
【问题描述】:
我有一个 UIButton 实例,即使触发附加到它的选择器,我也想获得触摸的确切位置。
按钮配置如下:
private var button: UIButton!
private func setupButton() {
button = UIButton(frame: frame)
button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)
}
@objc private func buttonPressed(_ button: BounceButton) {
// I need the location of the touch event that triggered this method.
}
请问有什么方法可以实现触发buttonPressed方法的触摸事件的定位?我对使用UIGestureRecognizer 实例犹豫不决,因为我实际上有多个具有不同tag 值的按钮,我用它们在buttonPressed 方法中执行不同的操作。
感谢您的任何建议。
【问题讨论】: