2009-09-17 54 views
2

我很難找到如何從tapEvent對象獲取水龍頭座標,該對象被傳遞給我的自定義處理程序(我沒有發現它是規範)。還有singleTap事件,它將自定義變量「X」傳遞爲「Y」,這是座標,我猜,但我無法在Emulator中調用該事件。Mojo.Event.tap - 如何獲取水龍頭座標?

問題是我正在研究一個應用程序,其中我有大元素,我需要知道用戶點擊的位置(可能是全局屏幕座標或我的元素的相對座標)。

下面是示例代碼:

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

非常感謝您的任何建議。

回答

4

敲擊事件的x和y座標位於事件的「向下」屬性中。

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); 
} 
+0

太棒了,正是我在尋找整整一天。奇怪的是,我沒有找到有關事件對象的文檔。 謝謝。 – 2009-09-18 08:57:38

+1

目前在SDK中的文檔中缺少*很多東西。 – 2009-09-18 14:05:38