Sundev Lohr
Sundev Lohr

Reputation: 21

Can't get pinch zoom and rotate gestures working on a container in Nativescript

I've been trying to get an image zoom, pinch and rotate working for a while now based off of this github project: https://github.com/vakrilov/native-script-pan-scale-demo/blob/master/app/main-page.js . But I can't quite get the trigonometry right. Also I'm unsure why there needs to be a translation during the onPinch method.

//initial touch during onPinch method
//args has the touch positions and item is the item to scale
if (args.state === 1) {
    var newOriginX = args.getFocusX() - item.translateX;
    var newOriginY = args.getFocusY() - item.translateY;

    var oldOriginX = item.originX * item.width;
    var oldOriginY = item.originY * item.height;

    item.translateX += (oldOriginX - newOriginX) * (1 - item.scaleX);
    item.translateY += (oldOriginY - newOriginY) * (1 - item.scaleY);

    item.originX = newOriginX / item.width;
    item.originY = newOriginY / item.height;

    startScale = item.scaleX;
}

Any help would be much appreciated.

Upvotes: 1

Views: 1093

Answers (1)

Narendra
Narendra

Reputation: 4574

instead of using item.width and item.height, you should use item.getMeasuredWidth() and item.getMeasuredHeight()

Upvotes: 2

Related Questions