【问题标题】:Vertical drag (touchMove) a titanium appcelerator view垂直拖动 (touchMove) 钛应用加速器视图
【发布时间】:2017-02-12 14:19:49
【问题描述】:

我想在钛应用加速器中垂直拖动视图并在屏幕上显示整个视图高度时停止。 在开始时,视图的高度为 140,底部为 -120,所以我可以有一个可以开始拖动的视图:

这就是我想要垂直拖动“myView”的方式,x 轴保留为 0,所以我只能从下到上拖动它,目的是在显示所有 myView 高度时停止拖动(所有 myView 都是可见的) .

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;
   console.log(e.x);
}

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

    var points = e.source.convertPointToView({
        x: e.x,
        y: e.y
    }, $.single);


$.myView.applyProperties({
        left: 0,
        top: points.y,
        opacity: 1
    });

/*------------------------------------------------------
* HERE I TRY TO DETECT IF myView HEIGHT IS SHOWN ENTIRELY
* is myView.top + myView.height > viewport ?
------------------------------------------------------*/
var t = $.myView.top + $.myView.height;
if( t >= HEIGHT ){
    alert('all myView is visible now ???');
    return; // <= why this has no effect ??
}

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

}
function onTouchEnd(e) {
  // check xDistance
}

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

使用此代码,我可以垂直拖动 myView,但在完全显示此高度时它不会停止。

我的第一个问题是: - 我怎么能说 myView 是否完全显示? - 如果显示所有 myView 高度,如何禁用垂直拖动到顶部?

谢谢

【问题讨论】:

    标签: titanium appcelerator appcelerator-titanium appcelerator-mobile


    【解决方案1】:

    函数onTouchMove应该是这样的。

    function onTouchMove(e) {
    
        /*------------------------------------------------------
        * HERE I TRY TO DETECT IF myView HEIGHT IS SHOWN ENTIRELY
        * is myView.top + myView.height > viewport ?
        ------------------------------------------------------*/
        var t = $.myView.top + $.myView.height;
        if( t >= HEIGHT ){
            alert('all myView is visible now ???');
            return; // <= why this has no effect ??
        }
    
        xDistance = cx - sx;
        var yDistance = cy - sy;
    
        var points = e.source.convertPointToView({
            x: e.x,
            y: e.y
        }, $.single);
    
    
        $.myView.applyProperties({
            left: 0,
            top: points.y,
            opacity: 1
        });
    
        cx = e.x;
        cy = e.y;
    
    }
    

    【讨论】:

    • 非常感谢,我试试这个
    • 您好,尝试您的代码,当视图完全可见时,拖动并没有停止。
    • 我的意思是如果条件不起作用,则内部的“返回”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-02
    • 1970-01-01
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多