Mojo.Event.tap - 如何获取点击坐标?

发布于 2024-08-05 14:20:11 字数 628 浏览 5 评论 0原文

我很难找出如何从 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?
}

非常感谢您的任何建议。

I am having difficulty with finding out how to get tap coordinates from tapEvent object, which is passed to my custom handler (I didn't find it's specification anyway). There is also singleTap event, which passes custom variables "X" as "Y", which is coordinates, i guess, but I can't invoke that one in Emulator.

The point is that I am working on one application, where I have big element and I need to know where exactly user tapped (it maybe global screen coordinate or relative coordinate of my element).

Here is example code:

//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?
}

Thank you very much for any suggestions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笏见 2024-08-12 14:20:11

点击事件的 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);
}

The x and y coordinates for the tap event are in the "down" property of the event.

Ex.

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文