我很难找到如何从 tapEvent 对象获取点击坐标,该对象被传递给我的自定义处理程序(无论如何我都没有找到它的规范)。还有 singleTap 事件,它将自定义变量“X”传递为“Y”,我猜这是坐标,但我无法在模拟器中调用该事件。
重点是,我正在开发一个应用程序,其中有一个大元素,我需要知道用户点击的确切位置(可能是全局屏幕坐标或元素的相对坐标)。
这里是示例代码:
//inside of assistant's setup method:
Mojo.Event.listen(this.controller.get('elem'), Mojo.Event.tap, this.listenSingleTap.bindAsEventListener(this));
//custom handler:
SomeAssistant.prototype.listenSingleTap = function(singleTapEvent){
this.someOtherMethod(singleTapEvent.x, singleTapEvent.y); //This is wrong and doesn't work - how I suppose to get tap coordinates?
}
非常感谢您的建议。
最佳答案
点击事件的 x 和 y 坐标位于事件的“down”属性中。
例如。
MyAssistant.prototype.setup = function() {
Mojo.Event.listen(this.controller.get('elem'), Mojo.Event.tap, this.handleTap.bind(this));
}
MyAssistant.prototype.handleTap = function(event) {
Mojo.Log.info("tap down at x: " + event.down.x + " y: " + event.down.y);
}
关于events - Mojo.Event.tap - 如何获取点击坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1438672/