3

当 touchmove 事件发生时,我试图在 Titanium iPhone 应用程序中获取 globalPoint,我使用以下代码获取 globalPoint

var x = parseInt(e.globalPoint.x, 10);

在我将 Titanium 3.0.2 GA 更新到 3.1.0 GA 之前它工作正常,更新后我运行应用程序出现以下错误

“未定义”不是对象(评估“e.globalPoint.x”)

我正在使用此代码来滑动窗口

var animateLeft = Ti.UI.createAnimation({
    left : 250,
    curve : Ti.UI.ANIMATION_CURVE_EASE_OUT,
    duration : 150
});

var animateRight = Ti.UI.createAnimation({
    left : 0,
    curve : Ti.UI.ANIMATION_CURVE_EASE_OUT,
    duration : 150
});

var touchStartX = 0;
var touchStarted = false;

$.innerwin.addEventListener('touchstart', function(e) {
    touchStartX = parseInt(e.x, 10);
});

$.innerwin.addEventListener('touchend', function(e) {
    touchStarted = false;
    if ($.win.left >= 150) {
        $.win.animate(animateLeft);
        hasSlided = true;
    } else {
        $.win.animate(animateRight);
        hasSlided = false;
    }
});

$.innerwin.addEventListener('touchmove', function(e) {
    var x = parseInt(e.globalPoint.x, 10);
    var newLeft = x - touchStartX;
    if (touchStarted) {
        if (newLeft <= 250 && newLeft >= 0) {
            $.win.left = newLeft;
        }
    }
    if (newLeft > 30) {
        touchStarted = true;
    }
});

$.button.addEventListener('singletap', function(e) {
    $.toggleSlider();
});

var hasSlided = false;
exports.toggleSlider = function() {
    if (!hasSlided) {
        $.win.animate(animateLeft);
        hasSlided = true;
    } else {
        $.win.animate(animateRight);
        hasSlided = false;
    }
}
4

2 回答 2

3

这已被弃用:

相反,您需要这样做(在这个非常人为的示例中),并使用convertPointToView方法:

var baseview = Ti.UI.createView({width : Ti.UI.FILL, height : Ti.UI.FILL});
var view = Ti.UI.createView({ width : 20, height : 20 });
view.addEventListener('touchmove', function(e) {
    var globalPoint = convertPointToView({x : e.x, y : e.y}, baseview);
});
于 2013-05-16T15:07:51.810 回答
0

Finally, I used following widget

http://www.danielsefton.com/2013/05/slider-menu-widget-v2-for-titanium-alloy/

于 2013-07-23T08:00:00.537 回答