Dragging an ImageView using touch events

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

I am working on a tutorial and it is not behaving correctly. I think it should be a fairly simple fix but I am new to the program so I may be wrong.

The tutorial is located at : http://www.packtpub.com/article/appcelerator-titanium-creating-animations-transformations-understanding-drag-drop

In the section "Dragging an ImageView using touch events, the first step is to make the image drag using the code:

imageViewFace.addEventListener('touchmove', function(e){
  imageViewMe.left = e.x;
  imageViewMe.top = e.y;
});
This code works but pulls the image from the top corner, so the next set of code is supposed to allow you to drag the image from it's center point. The code in the tutorial is...
imageViewFace.addEventListener('touchstart', function (e) {
  imageViewMe.ox = e.x - imageViewMe.center.x;
  imageViewMe.oy = e.y - imageViewMe.center.y;
});
 
imageViewFace.addEventListener('touchmove', function(e){
  imageViewMe.center = {
    x:(e.x - imageViewMe.ox),
    y:(e.y - imageViewMe.oy)
  };
});
However, when I run this code in the emulator, it doesn't drag at all. Does anyone know why this isn't working and what I could change to make it function? As I said, I'm new to the program... so any good tutorials on these and similar animations would also be helpful.

Many thanks, Andi

— asked 10 months ago by Andi Osiek
1 Comment
  • have you tried this code on android device?Sometimes such kind of issues occur due to slow performance of android emulator.

    — commented 10 months ago by Ashutosh Chaturvedi

2 Answers

I'm actually using the iPhone simulator (sorry I wasn't clear). It doesn't seem to be an issue with slow performance as the first section of code works and the second doesn't function at all.

Your Answer

Think you can help? Login to answer this question!