本文介绍了更改平移方向时,IOS 13没有引发平移事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个使用Hammer.js事件的自定义图像滑块.

I have a custom image slider using Hammer.js events.

我使用以下命令创建我的锤子"对象:

I use the following to create my 'hammer' object:

    const hammerPan = new Hammer(domElement,
    {
        // lock vertical scrolling when panning left to right
        touchAction: 'pan-y',

        recognizers: [
            // we don't care about vertical, but we want always to get panstart and panend
            // events so we use ALL to prevent unncesessary filtering from hammerjs
            [Hammer.Pan, { direction: Hammer.DIRECTION_ALL, threshold: 10 }]
        ]
    });

滑块(与大多数滑块一样)从左向右移动,但为避免阻止移动设备上的垂直滚动,我使用了 touchAction:'pan-y',因此我仍然可以滚动.

The slider (like most sliders) moves left to right, but to avoid blocking vertical scroll on mobile devices I use touchAction: 'pan-y' so I can still scroll.

在IOS 12中,一切正常-即使我向左摇摄,然后在松开手指之前向上移动手指.这样会触发一些垂直平移事件,但仍会以panend结尾..

In IOS 12 everything worked just fine - even if I panned left and then moved my finger up before releasing. This would trigger some vertical pan events but would still end in panend.

使用IOS 13(并且我有两部手机要比较),它不会给我最后的 panend 事件,因此我的幻灯片会卡住"一半.

With IOS 13 (and I have two phones to compare) it would not give me a final panend event so my slides would get 'stuck' halfway.

推荐答案

如果您不熟悉RxJS语法,那么我需要做的就是明确地添加 pancancel 事件.

Excuse RxJS syntax if this is unfamiliar to you, but all I needed to do was explicitly add the pancancel event.

const panUnfilteredRaw$ = fromEvent<HammerInput>(hammerPan as unknown as JQueryStyleEventEmitter,
                          'panstart panmove panend pancancel').pipe(share());

我以前没有这个,因为我从某个地方复制了它,或者我从没想过需要它.

I previously did not have this because either I copied it from somewhere, or I just never thought I needed it.

不确定IOS13是否有点挑剔(!),但如果更改平移方向,肯定会出现不同的行为-可以说这是一个错误.

Not sure if IOS13 is being more or less picky (!) but it's certainly got different behavior if you change direction of panning - so arguably it is a bug.

我还从检测 panend 切换到了 event.isFinal .

这篇关于更改平移方向时,IOS 13没有引发平移事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:34