我很难找到如何从tapEvent对象获取tap坐标,这会传递给我的自定义处理程序(我还没有找到它的规范)。还有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坐标位于“向下”状态。事件的财产。

实施例。

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);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top