2013-10-08 33 views
1

我發現touchmove事件似乎以我沒有想到的方式行事。似乎有多個我必須處理的座標系。我通讀了這張票:https://jira.appcelerator.org/browse/TIMOB-1277,但似乎沒有明確的解決方案。如何使用Titanium SDK/Appcellerator在Android上正確使用touchmove

我試過Vishal Duggal給出的關於使用convertPointToView的建議,但雖然它似乎在某些情況下有效,但在其他情況下,它似乎會讓事情變得更糟。有時,即使我的元素沒有從視圖層次結構中刪除,convertPointToView也會返回null。每個元素都有自己的座標系嗎?我看了這個文檔:http://docs.appcelerator.com/titanium/3.0/#!/guide/Layouts,_Positioning,_and_the_View_Hierarchy,但它似乎沒有解釋任何關於座標系的工作原理。

有時convertPointToView似乎也會返回不正確的值。比較我從e.x得到的值與從convertPointToView得出的值,當e.x似乎具有正確的值時,它似乎有時會跳到很高的數值。

有沒有人有任何好的參考資料我可以閱讀關於此?

我的基本問題是:使用觸摸事件的最佳做法是什麼?最重要的是,即使我觸摸的對象正在移動(對觸摸的響應),我如何確保從觸摸事件對象獲得的座標仍然有意義?

回答

0
try this code 

var circle = Ti.UI.createView({ 
height:300, 
backgroundColor: 'red', 
width:250 
}); 
$.win.add(circle); 

var item1 = Ti.UI.createImageView({ 
top:'0', 
id:'item1', 
//left:'0', 
width:'50', 
height:'50', 
zIndex:'1', 
backgroundColor:'green', 
image:'/burger_menu.png' 
}); 
circle.add(item1); 

var wth = item1.getWidth()/2; 
var hgt = item1.getHeight()/2; 

item1.addEventListener('touchmove', function(e) { 
touchMove(item1 , e); 

}); 

function touchMove(obj , e) 
{ 

var convertedPoint = obj.convertPointToView({x: e.x, y: e.y}, circle); 

    if(convertedPoint != null) 
    { 
       item1.animate({ 
       left: Math.round(convertedPoint.x/Ti.Platform.displayCaps.logicalDensityFactor) - wth, 
       top: Math.round(convertedPoint.y/Ti.Platform.displayCaps.logicalDensityFactor) - hgt , 
       duration: 1 
        });  
    } 
} 

$.win.open(); 
相關問題