0

私のアプリケーション内のビューverticalyをドラッグしたい、以下は私のコードです。 私はid = "win"と正方形のビュー(100x100)のウィンドウを持っています。チタンappceleratorのドラッグビュー

var window = $.win; 
var lastTouchPosition = 0; 
$.demo.addEventListener("touchstart", function(e){ 
    var touchPos = {x:e.x, y:e.y}; 
     lastTouchPosition = $.demo.convertPointToView(touchPos, window); 
}); 

$.demo.addEventListener("touchmove", function(e){ 
    var touchPos = {x:e.x, y:e.y}; 
    var newTouchPosition = $.demo.convertPointToView(touchPos, window); 

    $.demo.top += Number(newTouchPosition.y) - Number(lastTouchPosition.y); 
    $.demo.left += Number(newTouchPosition.x) - Number(lastTouchPosition.y); 
    //lastTouchPosition = newTouchPosition; 

}); 

私は、次の取得ビューをドラッグ開始WARN:[WARN]:無効な寸法値を(ナン)要求されました。代わりに寸法を定義しないでください。 と私の見解は動いていません。 特定の垂直位置の値に達すると、ビューをドラッグしてドラッグする方法を教えてください(例えば、ビューポートの下部など)

ありがとうございました。

答えて

0

私の代わりにこのようなウィンドウ/コンテナビューにタッチイベントを追加します。

var WIDTH = (OS_ANDROID) ? Ti.Platform.displayCaps.platformWidth/dpi : Ti.Platform.displayCaps.platformWidth; 
var HEIGHT = (OS_ANDROID) ? Ti.Platform.displayCaps.platformHeight/dpi : Ti.Platform.displayCaps.platformHeight; 
var sx = 0; 
var sy = 0; 
var cx = 0; 
var cy = 0; 
var xDistance = 0; 

function onTouchStart(e) { 
    // start movement 
    sx = e.x; 
    sy = e.y; 
    cx = e.x; 
    cy = e.y; 
} 

function onTouchMove(e) { 
    xDistance = cx - sx; 
    var yDistance = cy - sy; 

    var rotationStrength = Math.min(xDistance/(WIDTH), 1); 
    var rotationStrengthY = Math.min(yDistance/(HEIGHT), 1); 

    var rotationAngel = (2 * Math.PI * rotationStrength/16); 
    var scaleStrength = 1 - Math.abs(rotationStrength)/16; 
    var scaleStrengthY = 1 - Math.abs(rotationStrengthY)/16; 

    var scaleMax = Math.min(scaleStrength, scaleStrengthY); 
    var scale = Math.max(scaleMax, 0.93); 

    $.view_card_front.rotation = rotationAngel * 20; 
    $.view_card_front.translationX = xDistance; 
    $.view_card_front.setTranslationY(yDistance); 
    $.view_card_front.scaleX = scale; 
    $.view_card_front.scaleY = scale; 

    cx = e.x; 
    cy = e.y; 
} 

function onTouchEnd(e) { 
    // check xDistance 
} 

$.index.addEventListener("touchmove", onTouchMove); 
$.index.addEventListener("touchstart", onTouchStart); 
$.index.addEventListener("touchend", onTouchEnd); 

XMLに<View id="view_card_front"/>があるtouchEnabled:false

でこれは(あなたに素敵なスムーズなmoventを与えますこの例では回転)

+0

ありがとうmiga私はこれを試します – Rahajason

+0

Juste 1つの質問、なぜあなたは(HEIGHT)と(WIDTH)を入れますか、どの変数に対応していますか? – Rahajason

+0

申し訳ありませんが、私はそれらを追加しました。それは(私の場合は)ディスプレイの幅と高さです – miga

関連する問題