- iphone drag and drop weird jumpy movement
- -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
- UITouch *touch = [touches anyObject];
- NSString *touchClass = [NSString stringWithFormat:@"%@",[[touch view] class]];
- if ([touchClass isEqualToString:[NSString stringWithFormat:@"%@",[AnagramLetter class]]]) {
- NSLog(@"start moving");
- }
- }
- -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
- UITouch *touch = [touches anyObject];
- NSString *touchClass = [NSString stringWithFormat:@"%@",[[touch view] class]];
- CGPoint location = [touch locationInView:touch.view];
- if ([touchClass isEqualToString:[NSString stringWithFormat:@"%@",[AnagramLetter class]]]) {
- NSLog(@"touch view centre (x,y) - (%f,%f)",touch.view.center.x,touch.view.center.y);
- NSLog(@"location (x,y) - (%f,%f)",location.x,location.y);
- touch.view.center = location;
- }
- }
- -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
- UITouch *touch = [touches anyObject];
- NSString *touchClass = [NSString stringWithFormat:@"%@",[[touch view] class]];
- if ([touchClass isEqualToString:[NSString stringWithFormat:@"%@",[AnagramLetter class]]]){
- NSLog(@"Now stop moving!");
- }
- }
- [touch locationInView:[touch.view superview]];
- if ([touchClass isEqualToString:[NSString stringWithFormat:@"%@",[AnagramLetter class]]]) {
- UITouch * touch = [touches anyObject];
- CGPoint previous = [touch previousLocationInView:[touch.view superview]];
- CGPoint current = [touch locationInView:[touch.view superview]];
- CGPoint displacement = CGPointMake(current.x - previous.x, current.y - previous.y);
- CGPoint center = touch.view.center;
- center.x += displacement.x;
- center.y += displacement.y;
- touch.view.center = center;
- }