Skip to content

Instantly share code, notes, and snippets.

@QGao
Created December 2, 2011 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save QGao/1425266 to your computer and use it in GitHub Desktop.
Save QGao/1425266 to your computer and use it in GitHub Desktop.
A sample of using convertPointToView
var win = Ti.UI.createWindow(
{ backgroundColor: 'black' }
);
var center1 = {'x': 100, 'y':100};
var center2 = {'x': 100, 'y':250};
var lastIndex = 1;
var background = Ti.UI.createView({ backgroundColor:"#444444", });
var view = Ti.UI.createView({ backgroundColor:'red', center:center1, width:100, height:100, zIndex:lastIndex++, });
var view2 = Ti.UI.createView({ backgroundColor:'green', center:center2, width:100, height:100, zIndex:lastIndex, });
background.addEventListener('touchstart', function(e){
var bgPoint = background.convertPointToView(e, background);
Ti.API.debug("Background Point: " + bgPoint.x + "," + bgPoint.y);
view.center = bgPoint;
view.backgroundColor='blue';
});
view.addEventListener('touchend', function(e){
view.center = center1;
view.backgroundColor = 'red';
});
win.add(background);
win.add(view);
win.add(view2);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment