Relative tap position


#1

Hello. I would like to ask you if is possible detect relative tap coordinates of image(or any element) starting by x=0 and y=0.

I need detect size of image (width and height) too.

Is it in Nativescript possible? For example I made it in HTML and JS

https://jsfiddle.net/5pp9pqf2/23/image


#2

https://docs.nativescript.org/ui/gestures#touch

var gestures = require("ui/gestures");
var labelModule = require("ui/label");
var label = new labelModule.Label();
label.on(gestures.GestureTypes.touch, function (args) {
    console.log("Touch: x: " + args.getX() + " y: " + args.getY());
});

#3

Thanks but I need it in Angular2/Typescript. And I need to detect size of element.


#4

Only the import statement changes for TypeScript. You can directly attach touch listener to your elements declared in html file, just like any other events tap or loaded.

Use view.getActualSize() to find the size.