目的
viewをドラッグ移動できるようにします。
方法
touchmoveイベントのみで処理が可能です。
しかし、touchmoveだけで行うと処理が早すぎて?ドラッグの初期動作でかなりviewがぶれてしまいます。
その対策として、counterをかませて遅延処理を搭載しています。
$.frontImage.addEventListener(‘touchmove’,function(e){ fcounter++; if(fcounter && fcounter % 5 == 0){ touchMove($.frontImage , e, wth1, hgt1); } if(fcounter > 100){ fcounter = 0; } }); |
function touchMove(obj , e, wth, hgt){ var convertedPoint = obj.convertPointToView({x: e.x, y: e.y}, $.allView); if(convertedPoint != null){ obj.animate({ left: Math.round(convertedPoint.x/Ti.Platform.displayCaps.logicalDensityFactor) – wth, top: Math.round(convertedPoint.y/Ti.Platform.displayCaps.logicalDensityFactor) – hgt , duration: 1 }); } } |
styleについて
<View id=”allView”>
<View id=”frontImage” />
<View id=”rearImage” />
</View>
変数について
wth1:移動するviewのx座標の中心値
hgt1:移動するviewのy座標の中心値
説明が雑ですみません・・・
コメント