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

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 1.81 KB  |  hits: 18  |  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. iphone drag and drop weird jumpy movement
  2. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  3.     UITouch *touch = [touches anyObject];
  4.     NSString *touchClass = [NSString stringWithFormat:@"%@",[[touch view] class]];
  5.  
  6.     if ([touchClass isEqualToString:[NSString stringWithFormat:@"%@",[AnagramLetter class]]]) {
  7.         NSLog(@"start moving");
  8.     }
  9. }
  10.  
  11. -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  12.     UITouch *touch = [touches anyObject];
  13.     NSString *touchClass = [NSString stringWithFormat:@"%@",[[touch view] class]];
  14.     CGPoint location = [touch locationInView:touch.view];
  15.     if ([touchClass isEqualToString:[NSString stringWithFormat:@"%@",[AnagramLetter class]]]) {
  16.         NSLog(@"touch view centre (x,y) - (%f,%f)",touch.view.center.x,touch.view.center.y);
  17.         NSLog(@"location (x,y) - (%f,%f)",location.x,location.y);
  18.         touch.view.center = location;
  19.     }
  20. }
  21.  
  22. -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
  23.     UITouch *touch = [touches anyObject];
  24.     NSString *touchClass = [NSString stringWithFormat:@"%@",[[touch view] class]];
  25.  
  26.     if ([touchClass isEqualToString:[NSString stringWithFormat:@"%@",[AnagramLetter class]]]){
  27.         NSLog(@"Now stop moving!");
  28.     }
  29. }
  30.        
  31. [touch locationInView:[touch.view superview]];
  32.        
  33. if ([touchClass isEqualToString:[NSString stringWithFormat:@"%@",[AnagramLetter class]]]) {
  34.         UITouch * touch = [touches anyObject];
  35.         CGPoint previous = [touch previousLocationInView:[touch.view superview]];
  36.         CGPoint current = [touch locationInView:[touch.view superview]];
  37.         CGPoint displacement = CGPointMake(current.x - previous.x, current.y - previous.y);
  38.  
  39.         CGPoint center = touch.view.center;
  40.         center.x += displacement.x;
  41.         center.y += displacement.y;
  42.         touch.view.center = center;
  43. }