Simplest way to detect a pinch

前端 未结 7 1991
清酒与你
清酒与你 2020-11-28 19:29

This is a WEB APP not a native app. Please no Objective-C NS commands.

So I need to detect \'pinch\' events on iOS. Problem is every plugin or metho

相关标签:
7条回答
  • 2020-11-28 20:21

    You want to use the gesturestart, gesturechange, and gestureend events. These get triggered any time 2 or more fingers touch the screen.

    Depending on what you need to do with the pinch gesture, your approach will need to be adjusted. The scale multiplier can be examined to determine how dramatic the user's pinch gesture was. See Apple's TouchEvent documentation for details about how the scale property will behave.

    node.addEventListener('gestureend', function(e) {
        if (e.scale < 1.0) {
            // User moved fingers closer together
        } else if (e.scale > 1.0) {
            // User moved fingers further apart
        }
    }, false);
    

    You could also intercept the gesturechange event to detect a pinch as it happens if you need it to make your app feel more responsive.

    0 讨论(0)
提交回复
热议问题