“触摸移动"安卓系统事件:Transformer Prime [英] The "touchmove" event on android system: Transformer Prime

查看:38
本文介绍了“触摸移动"安卓系统事件:Transformer Prime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作 Transformer Pad 并开发绘图板.我使用 PhoneGap(javascript) 来编写代码而不是 JAVA.

I am working on a Transformer Pad and developing a drawing plate. I use PhoneGap(javascript) to write the code instead of JAVA.

但是 touchmove 事件很奇怪.

But the touchmove event is quite weird.

我认为当我在键盘上移动手指时,它会不断收集我触摸画布.但事实并非如此!太荒谬了,它只收集1"坐标:我的手指移动到画布上的第一个点.

I think as I move my finger on the pad, it will continuously to collect the coordinates which I touch on the canvas. BUT IT DOES NOT! It's ridiculous, it only collect "1" coordinate: the first point on the canvas my finger moves to.

这是我关于触摸和移动事件"的代码:

Here are my code about the "Touch && Move event":

function touchStart(event){
    if (event.targetTouches.length == 1) {
    var touch = event.targetTouches[0];     

        if (event.type == "touchstart") {
            line_start_x= touch.pageX-  canvas_org_x;
            line_start_y= touch.pageY-  canvas_org_y;
            context.beginPath();                        
            context.moveTo(line_start_x, line_start_y); 

        }//if           
    }//if 1
}//function.

function Touch_Move(event){
    line_end_x= event.touches[0].pageX-  canvas_org_x;
                line_end_y= event.touches[0].pageY-  canvas_org_y;
                context.lineTo(line_end_x, line_end_y);
                context.stroke();
                test++;                 
}

我不知道为什么每次我在垫子上移动手指,试图画一条线、曲线或任何东西我想.当手指移动时,只会出现一个非常短的片段.所以我在这个js文件的开头声明了一个变量:var test=0".我发现虽然我在pad上移动手指没有离开或停止,但test"的值仍然是1.这意味着我在上面移动了手指.但它没有连续触发事件:Touch_Move".

I don't know why each time I move my finger on the pad, trying to draw a line, curve, or anything I want. As the finger moves, only a VERY SHORT segment appears. So I declare a variable:"var test=0" in the beginning of this js file. I found that although I move my finger on the pad without leaving it or stopping, the value of "test" remains 1. It means that I move my finger on it. But it doesn't continuously to trigger the event: "Touch_Move".

我现在能做什么?我需要一个相应的事件来在触摸板上鼠标移动".至少,事件必须不断被触发.

What can I do now? I need a corresponding event to "mousemove" on touch pad. At least, the event has to continuously be triggered.

                                                                   Thank you!

推荐答案

哦,天哪.我终于找到了答案:请参考本站.

Oh, Jesus. I finally find the answers: Please take reference for this site.

如果您在 Android 系统上工作,请记住touchmove"仅在您的手指上触发一次围绕垫移动.所以如果你想画一条线什么的,你必须这样做:

If you work on an Android System,remember the 'touchmove' only fire ONCE as your finger moves around the pad. So if you wanna draw a line or something, you have to do this:

function onStart ( touchEvent ) {
if( navigator.userAgent.match(/Android/i) ) {   // if you already work on Android system, you can        skip this step
touchEvent.preventDefault();     //THIS IS THE KEY. You can read the difficult doc released by W3C to learn more.
}

如果你有更多的时间,你可以阅读 W3C 关于介绍'movetouch',真的很难理解.医生很烂.

And if you have more time, you can read the W3C's document about introducing the 'movetouch', it is REALLY hard to understand. The doc sucks.

这篇关于“触摸移动"安卓系统事件:Transformer Prime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆