I have an image in a view which contains a 9x9 grid. I want to move the object along the grid, which is made up of a column array(9) inside another array(9), using a pan movement. The image should move square to square in the grid. The code below is what I have so far. The problem is the image jumps 3 - 4 squares at a time. It is much too sensitive. Can anyone shed some light as to why and make some suggestions as to what to do to fix this sensitivity issue issue?
Code which works:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self.view];
// Do not move if touch is off the grid
if (gestureStartPoint.x < 0 ||
gestureStartPoint.x > 450 ||
gestureStartPoint.y < 0 ||
gestureStartPoint.y > 450) {
canMove = NO;
}else {
canMove = YES;
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.view];
double thresholdX = 50;
if (canMove) {
deltaX = (int)(currentPosition.x - gestureStartPoint.x);
if (deltaX > thresholdX) {
deltaX = 0;
if([self blockCanMoveXDir:1]){
[cBlock movX:1];
}
// Resets start point
gestureStartPoint = currentPosition;
NSLog(@"-------------> Block Moved");
} else if(deltaX < 0 && fabs(deltaX) > thresholdX) {
deltaX = 0;
if([self blockCanMoveXDir:-1]){
[cBlock movX:-1];
}
gestureStartPoint = currentPosition;
}
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
canMove = NO;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
canMove = NO;
}