简体   繁体   English

PIXI - 禁用 preventDefault 触摸事件在 Android 设备上不起作用

[英]PIXI - disabled preventDefault touch events not working on Android devices

Since I´m working on a project where I need to be able to drag objects around my canvas but also to scroll the entire page by dragging the actual canvas 'background' behind my PIXI Sprites, i followed the findings of this guy here:由于我正在处理一个项目,我需要能够在我的画布周围拖动对象,而且还需要通过拖动 PIXI Sprites 后面的实际画布“背景”来滚动整个页面,因此我在这里遵循了这个人的发现:

https://github.com/pixijs/pixi.js/issues/2483 : https://github.com/pixijs/pixi.js/issues/2483

By default, the Pixi canvas/display-area cannot be used to scroll the webpage that contains it.默认情况下,Pixi canvas/display-area 不能用于滚动包含它的网页。 Which is important on touch screens.这在触摸屏上很重要。 (eg. If you use the rest of the web-page to pinch-zoom into the Pixi canvas, you can become trapped and unable to zoom back out (or pan away), because there's no non-Pixi-canvas area of the page to "grab" with your pinch gesture). (例如,如果您使用网页的其余部分来缩放 Pixi 画布,您可能会陷入困境并且无法缩小(或平移),因为页面上没有非 Pixi 画布区域用捏合手势“抓住”)。

To enable this functionality, I use autoPreventDefault.为了启用此功能,我使用了 autoPreventDefault。 But this comes with some undesirable side-effects, like scroll/pinch-zoom actions over the canvas registering "taps" or clicks in a way that doesn't make sense.但这会带来一些不受欢迎的副作用,例如画布上的滚动/缩放操作以没有意义的方式注册“点击”或点击。 (ie. I'm attempting to zoom or scroll the outer page at that point, not interact with the Pixi canvas) (即。此时我正在尝试缩放或滚动外页,而不是与 Pixi 画布交互)

To work around that, I modify and compile my own custom version of Pixi where I can apply preventDefault in a more granular way...为了解决这个问题,我修改并编译了我自己的 Pixi 自定义版本,我可以在其中以更精细的方式应用 preventDefault ...

To get page-scrolling functionality it seems I only need to preventDefault in the InteractionManager.prototype.onTouchEnd function.为了获得页面滚动功能,我似乎只需要在 InteractionManager.prototype.onTouchEnd 函数中阻止默认。 Whereas autoPreventDefault will also preventDefault on 3 other events.而 autoPreventDefault 还将在其他 3 个事件上防止默认。 (onMouseDown, onTouchMove, onTouchStart). (onMouseDown、onTouchMove、onTouchStart)。

Leaving autoPreventDefault = false and applying preventDefault only to onTouchEnd, gives me the functionality I need.保留 autoPreventDefault = false 并仅将 preventDefault 应用于 onTouchEnd,为我提供了所需的功能。 But it'd be nice to not have to customize and rebuild Pixi in this way every release.但是最好不必在每个版本中都以这种方式自定义和重建 Pixi。 (Sorry if there's something else I'm missing here; I don't completely understand the event system in Pixi, or what else to do about this scroll-touch problem) (对不起,如果我在这里遗漏了其他东西;我不完全了解 Pixi 中的事件系统,或者对于这个滚动触摸问题还有什么办法)

So i disabled e.preventDefault() on 'onTouchStart' and on 'onMouseMove' but left it as is on 'onTouchEnd'所以我在“onTouchStart”和“onMouseMove”上禁用了 e.preventDefault() 但在“onTouchEnd”上保持原样

This works perfect on IOS devices but not on Android, the only exception being a Samsung A7 using Adblock browser (fails on Chrome).这在 IOS 设备上非常有效,但在 Android 上却不是,唯一的例外是使用 Adblock 浏览器的三星 A7(在 Chrome 上失败)。

Would really appreciate some help on this.真的很感激这方面的一些帮助。

TLDR:域名注册地址:

Disabling PIXI´s e.preventDefault on onTouchStart and onMouseMove works on IOS devices and lets me scroll the page by draggin my canvas around but not on Android devices.在 onTouchStart 和 onMouseMove 上禁用 PIXI 的 e.preventDefault 适用于 IOS 设备,并让我通过拖动画布来滚动页面,但不适用于 Android 设备。

My solution for that was to use我的解决方案是使用

renderer.plugins.interaction.autoPreventDefault = false

This should work on iOS and Android.这应该适用于 iOS 和 Android。 Docs for autoPreventDefault reads: autoPreventDefault 的文档如下:

Should the manager automatically prevent default browser actions.管理器是否应自动阻止默认浏览器操作。

Using PIXI 4.5.6.使用 PIXI 4.5.6。 Take a look at the docs: http://pixijs.download/dev/docs/PIXI.CanvasRenderer.html#plugins http://pixijs.download/dev/docs/PIXI.interaction.InteractionManager.html看看文档: http : //pixijs.download/dev/docs/PIXI.CanvasRenderer.html#plugins http://pixijs.download/dev/docs/PIXI.interaction.InteractionManager.html

使用renderer.plugins.interaction.autoPreventDefault=true应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM