Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 1st, 2012  |  syntax: None  |  size: 0.67 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Recognize that in which direction a control dragged
  2. @interface YourImageView : UIImageView
  3. {
  4.     CGPoint previousPt;
  5.     //Other iVars.
  6. }
  7. @end
  8.  
  9. @implementation YourImageView
  10.  
  11. - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  12. {  
  13.     previousPt = [[touches anyObject] locationInView:self.view];
  14. }
  15.  
  16. - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  17. {
  18.     const CGPoint p = [[touches anyObject] locationInView:self.view];
  19.     if (previousPt.x > p.x)
  20.     {
  21.         //Dragged right to left
  22.     }
  23.     else if  (previousPt.x < p.x)
  24.     {
  25.         //Dragged left to right
  26.     }
  27.     else
  28.     {
  29.         //no move
  30.     }
  31.     //Do the same thing for y-direction
  32. }