47
Views
2
Comments
How to pinch-zoom an image in a mobile app
Question
Application Type
Mobile

I am trying to pinch-zoom (and preferably double-click-zoom) an image on a mobile app (not a PWA). However, it seems as if this is turned off by the Cordova wrapper, since pinching an image does not zoom in. Are there any ways to make this work?

2023-02-10 10-15-37
Pradeep Dubey
AI Generated

To enable pinch-zoom and double-click zoom functionality for images in an OutSystems mobile app, you can follow these steps:

Custom JavaScript Solution:

  • One way to achieve pinch-zoom and double-click zoom functionality is by implementing custom JavaScript code in your OutSystems mobile app.
  • You can utilize JavaScript libraries like Hammer.js or other touch event libraries to handle pinch-zoom gestures on the images.

Cordova Plugin Integration:

Another approach is to integrate a Cordova plugin that specifically enables pinch-zoom functionality for images in your mobile app.

In your OutSystems app, create a custom action that will handle the pinch-zoom and double-click-zoom functionality. This action should use JavaScript to detect the pinch-zoom and double-click events and adjust the image size accordingly.

In the custom action, use the following code to detect the pinch-zoom and double-click events:

// Detect pinch-zoom

document.addEventListener('gesturestart', function(event) {

    if (event.scale > 1) {

        // Zoom in

    } else {

        // Zoom out

    }

});

// Detect double-click

document.addEventListener('dblclick', function(event) {

    if (event.target.tagName === 'IMG') {

        // Toggle between zoomed-in and zoomed-out state

    }

});

In the custom action, use the following code to adjust the image size:

// Zoom in

function zoomIn() {

    var img = event.target;

    img.style.transform = 'scale(2)';

}


// Zoom out

function zoomOut() {

    var img = event.target;

    img.style.transform = 'scale(1)';

}

In your OutSystems app, add the custom action to the image element where you want to enable pinch-zoom and double-click-zoom.




This answer was AI-generated. Please read it carefully and use the forums for clarifications
2021-02-16 20-34-58
Remco Snijders
 
MVP

I have used and customized the Custom Touch Events extension, which uses Hammer JS, to achieve the desired result.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.