Open A-ZC-Lau opened 7 years ago
Having the same problem. Is there a way to signal an end to the first gesture once it detects the opposite gesture being done?
mc.on('pinchstart pinchin pinchout', function (e) {
console.log(e.type,e.scale)
})
pinchin 0.921106764839676
pinchin 0.9190911462876488
pinchin 0.9178858750778195
pinchin 0.9168796106434124
pinchin 0.9158738724549084
pinchin 0.9154818252617791
pinchin 0.9144773010583551
pinchin 0.9137039677127727
pinchin 0.9131315050799014 // !!!!
pinchin 0.9145637167808034
pinchin 0.9168084914552729
pinchin 0.922487166400679
pinchin 0.9231129173467861
pinchin 0.9255477734548514
pinchin 0.9279827918593396
pinchin 0.9336662799498239
pinchin 0.9361026609184049
pinchin 0.9417886254371779
pinchin 0.9442259320698835
pinchin 0.9499143427210271
pinchin 0.9523528206547633
pinchin 0.9572305537414733
pinchin 0.959848528003095
pinchin 0.9647270861160608
pinchin 0.9655403288964608
pinchin 0.9687935591257139
pinchin 0.9714110475700877
pinchin 0.9738511404322971
pinchin 0.9771051396443653
pinchin 0.9795459062518832
pinchin 0.9815262512885534
pinchin 0.9839666159203826
pinchin 0.9859480658401607
pinchin 0.9882109692307326
pinchin 0.9900148787991505
pinchin 0.9932688521618154
pinchin 0.99425902608455
pinchin 0.9981506323520188
pinchin 0.9991402733833235
pinchout 1.0005920579587153
pinchout 1.0015813552782067
As the above comment illustrates, I got it to work pretty reliably by doing the following:
let lastScale = 1;
....
mc.on('pinchout pinchin', e => {
if (e.scale < lastScale) {
// zoom in
handlePinchZoom(1);
} else if (e.scale > lastScale) {
// zoom out
handlePinchZoom(-1);
}
lastScale = e.scale;
});
mc.on('pinchend', e => {
lastScale = 1;
});
So what happens is, if you trigger a pinchin first (pulling two fingers together), then you start pinching out (pulling two fingers away) it'll continue triggering pinchin. Vice versa for pinchout.