【问题标题】:How to use touchmove correctly on Android with Titanium SDK / Appcellerator如何通过 Titanium SDK / Appcellerator 在 Android 上正确使用 touchmove
【发布时间】:2013-10-08 19:30:07
【问题描述】:

我发现 touchmove 事件的行为方式似乎出乎我的意料。我似乎必须处理多个坐标系。我通读了这张票:https://jira.appcelerator.org/browse/TIMOB-1277,但似乎没有明确的解决方案。

我尝试了 Vishal Duggal 给出的使用 convertPointToView 的建议,但虽然它在某些情况下似乎有效,但在其他情况下似乎更糟。有时即使我的元素都没有从视图层次结构中删除,convertPointToView 也会返回 null。每个元素都有自己的坐标系吗?我查看了这个文档:http://docs.appcelerator.com/titanium/3.0/#!/guide/Layouts,_Positioning,_and_the_View_Hierarchy,但它似乎没有解释任何关于坐标系如何工作的内容。

有时 convertPointToView 似乎也返回了不正确的值。比较我从 e.x 得到的值与从 convertPointToView 得到的值,当 e.x 似乎具有正确的值时,它似乎有时会跳到一个高数字。

有没有人有什么好的参考资料可供我阅读?

我的基本问题是:使用触摸事件的最佳做法是什么?最重要的是,即使我正在触摸的对象正在移动(响应触摸),我如何确保从触摸事件对象获得的坐标仍然有意义?

【问题讨论】:

    标签: javascript android mobile titanium appcelerator


    【解决方案1】:

    查看我编写的这个示例,以测试如何将 convertPointToView 与触摸移动事件一起使用。 https://gist.github.com/tripitakit/7303233#file-ti-touches-kiss-js

    【讨论】:

    • 它不是处理触摸源对象的移动,但它帮助我处理如果从错误的 obj 监听时收到的奇怪坐标。
    【解决方案2】:
    try this code
    
    var circle = Ti.UI.createView({
    height:300,
    backgroundColor: 'red',
    width:250
    });
    $.win.add(circle);
    
    var item1 = Ti.UI.createImageView({
    top:'0',
    id:'item1',
    //left:'0',
    width:'50',
    height:'50',
    zIndex:'1',
    backgroundColor:'green',
    image:'/burger_menu.png'
    });
    circle.add(item1);
    
    var wth = item1.getWidth()/2;
    var hgt = item1.getHeight()/2;
    
    item1.addEventListener('touchmove', function(e) {
    touchMove(item1 , e);
    
    });
    
    function touchMove(obj , e)
    {
    
    var convertedPoint = obj.convertPointToView({x: e.x, y: e.y}, circle);
    
        if(convertedPoint != null)
        {
                    item1.animate({
                    left: Math.round(convertedPoint.x/Ti.Platform.displayCaps.logicalDensityFactor) - wth,  
                    top: Math.round(convertedPoint.y/Ti.Platform.displayCaps.logicalDensityFactor) - hgt ,
                    duration: 1 
                       });      
        }
    }
    
    $.win.open();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多