get the x,y coordinates in screen or window coordinates, not karen view

You must Login before you can answer or comment on any questions.

I have the following layout: window1 contains View1 View1 contains View2 View2 contains Button1

If I attach View1.addEventListener('touch move) - when the touch will be started on Button1, I will get x,y as relative to View2. How can I get X,Y in terms of view1, even though the touch is on Button1.

It seams that even if I attach the event of View1, the source of the event is still the button.

Tested this on iOS

Thanks

— asked 9 months ago by Ryan popa
1 Comment
  • Rather than trying to explain something like this, its much easier to post a code example that duplicates the issue that you're having. Couple the code with the proper information from QA Checklist and you'll receive many more answers of high quality.

    — commented 9 months ago by Anthony Decena

1 Answer

Accepted Answer

I agree with Anthony that posting a code can result in more quality answers but you may have other things going in the code so you probably just explained what the issue is.

Anyways, something like this should work

var finalX = view2.left + event.x;
var finalY = view2.top + event.y;
Again, you will have to just play with it a little bit but basically add the lefts and tops until to get to the reference point you are looking for.

If this does not help, try posting code with follow up question.

Your Answer

Think you can help? Login to answer this question!