[Tinanium]androidでviewのドラッグ(draq)移動

目的

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座標の中心値

説明が雑ですみません・・・

日々のITエンジニアの日常作業を発信しています。
また、様々なレビュー記事も書いていますので、ぜひご活用ください。

基本的に投稿は毎週月曜日の午前です。
2025年2月中旬より手術の為に入院をしていましたが、ようやくブログ投稿の復帰ができそうです。
4月中旬~下旬には再開予定です。

では今週も頑張っていきましょう!
ガンバー!!

Titanium(AppCerorater)

コメント