在" touchmove"事件的android系统:变压器总理 [英] The "touchmove" event on android system: Transformer Prime

查看:190
本文介绍了在" touchmove"事件的android系统:变压器总理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个变压器垫和开发的绘图板。 我使用的PhoneGap(JavaScript的)写的code,而不是JAVA。

但touchmove事件颇为怪异。

我想,我将我的手指在键盘,它会不断地收集坐标我 触摸画布上。不过,这并不! 这是荒谬的,只收取1的坐标:在画布上的第一点我的手指移动到。

下面是我的code有关触摸及与放大器;将事件:

 函数touchStart(事件){
    如果(event.targetTouches.length == 1){
    变种触摸= event.targetTouches [0];

        如果(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);

        }//如果
    } //如果1
}//功能。

功能TOUCH_MOVE(事件){
    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();
                测试++;
}
 

我不知道为什么,每次我提出我的手指在键盘,试图绘制直线,曲线,或任何 我要。随着手指的移动,只出现很短的片段。所以,我声明一个变量:VAR测试= 0在这个js文件的开头。我发现,虽然我将我的手指在键盘没有留下它或停止,测试的值保持1.这意味着我将我的手指上。但它不 连续触发的事件:TOUCH_MOVE

现在我该怎么办?我需要一个相应的事件在触控板鼠标移动。至少,事件必须连续被触发。

 谢谢!
 

解决方案

呵呵,耶稣。我终于找到了答案: 请大家参考这个网站。

如果你工作在一个Android系统,一旦记住了touchmove只火为你的手指 绕着垫。所以,如果你想画一条线什么的,你必须要做到这一点:

 函数ONSTART(的TouchEvent){
如果(navigator.userAgent.match(/安卓/ I)){//如果在Android系统已经正常工作,则可以跳过这一步
的TouchEvent preventDefault()。 //这是关键。你可以阅读发布的W3C了解更多艰难的文档。
}
 

如果你有更多的时间,你可以阅读W3C的文档有关介绍 movetouch',这实在是令人费解。该文档吮吸。

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

But the touchmove event is quite weird.

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++;                 
}

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.

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.
}

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.

这篇关于在" touchmove"事件的android系统:变压器总理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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