我正在开发 html5 游戏,在 chrome、firefox、safari、Ipad IO6、android 中一切都运行良好,但在 IOS7 和 Iphone4 中运行不佳。触摸事件效果不好。即使简单的“e.preventdefault”也无法处理双触摸问题,它会不断放大和缩小。不像其他设备。 有人有同样的问题吗??
它是我代码的一部分..抱歉不能写太多..我有一些保密协议(protocol)
var ua = navigator.userAgent.toLowerCase();
var checks = Boolean(ua.match(/android/))||
Boolean(ua.match(/ipod/))||
Boolean(ua.match(/ipad/))||
Boolean(ua.match(/tablet/))||
Boolean(ua.match(/tablet pc/))
var touchable = checks && (typeof (document.ontouchstart) != 'undefined');
if(touchable){
canvas.addEventListener('touchstart',mouseDown,false);
canvas.addEventListener('touchmove',mouseMove,false);
document.addEventListener('touchend',mouseUp,false);
}else{
canvas.addEventListener('mousedown',mouseDown,false);
canvas.addEventListener('mousemove',mouseMove,false);
document.addEventListener('mouseup',mouseUp,false);
}
function getMousePos(evt)
{
if(touchable && evt.touches.length>1)return;
if(touchable)evt = evt.changedTouches[0];
var rect = canvas.getBoundingClientRect();
return {
x: (evt.clientX - rect.left) / game.scale.x,
y: (evt.clientY - rect.top) / game.scale.y
};
}
function mouseDown(e)
{
var mousePos = getMousePos(e);
alert(mousePos.x + "," + mousePos.y);
e.preventDefault();
}
最佳答案
我在运行 iOS7 的 iPhone4 上测试 PhoneGap 应用程序时确实遇到了这个问题。我使用 fastclick.js 删除了 300 毫秒的延迟,将所有转换设置为 0,删除了悬停延迟,但滚动时仍然存在明显的延迟。不幸的是,这个问题似乎与尝试运行 iOS7 的 iPhone4 硬件直接相关。从技术上讲,虽然 iOS7 可在 iPhone4 上使用,但 iOS7 的设计并未考虑到 iPhone4。
关于javascript - 触摸事件在 IOS 7 Iphone 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20063897/