【发布时间】:2016-04-30 07:43:27
【问题描述】:
我在视图上设置了几个鼓垫,它们都连接到一个 drumPadPlay IBAction 方法。我想确定用户在发送器按钮内按下的 y 轴位置,以调整鼓垫播放的音量。我正在使用 swift。
在将其标记为重复问题之前,我已经引用了这个问题,并且该解决方案不适用于当前版本的 swift,或者我不知道在答案显示为“buttonView”的地方放什么。 Detect what is the location of the tap/press inside UIButton inside sender action method
@IBAction func drumPadPressed(sender: BNDrumPad, event: UIEvent) {
//...code for function here
// get any touch on the buttonView
if let touch = event.touchesForView(sender.)?.anyObject() as? UITouch {
// print the touch location on the button
println(touch.locationInView(buttonView))
}
//...more code for function here
}
这是我的代码 - 错误是“使用未解析的标识符 'buttonView'” 我不知道 buttonView 用什么。我试过 sender.superview !并搜索了发件人的属性/功能列表,但找不到任何看起来有帮助的东西。
【问题讨论】:
-
您链接到的答案是正确的。也许您可以编辑您的问题以显示您尝试过的代码以及您遇到的错误/问题。
-
我编辑了问题以包含代码示例。我觉得这是一个如此简单的答案,另一个答案假设它知道用什么替换 buttonView 但我无法弄清楚。