How To Get The Touch Point (top And Left) Irrespective Of The Views, Windows In Titanium
Solution 1:
consider you have a window win thats going to fire the click event like that:
win.addEventListener('click',function(e){
var myPopUp = createPopUp({
left: e.x,
top: e.y
});
myPopUp.open();
});
your popup could be created like that:
createPopUp = function(_args){
var popup = Titanium.UI.createWindow({
backgroundColor: 'red', /* a backgroundImage could be better */
height: '250dp',
width: '250dp',
top: _args.top, /* manually adjusted */
left: _args.left,
opacity: 0.7/* for a nice transparency*/
});
return popup;
};
this works at android and iphone. the top values seems to be a little unprecise but in general it works.
Solution 2:
In regards to getting the touch coordinates for the parent view you should attach the event listener to the parent view (or both if you can't get the source and need different actions) because if I'm correct the touch event (or any other for event that matter) should propagate to parent/child views too. Then you can simply get the e.source.top
and e.source.left
values as you need.
Solution 3:
You can place this way PopupWindow, using its showAtLocation method.
This allows to place the window in desired position, relative to your main view. And you know where user clicked on your main view.
Post a Comment for "How To Get The Touch Point (top And Left) Irrespective Of The Views, Windows In Titanium"