سؤال

أواجه صعوبة في معرفة كيفية الحصول على إحداثيات النقر من كائن 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 لحدث TAP موجودة في خاصية "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);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top