I have started a new IOS app and I have a problem in my code. Description about the app: At the middle of the screen there placed a circle, when I tap the screen the circle starting move to the point that i tapped there. I have program it and its work very well, but there is one more thing: when i tap in another point on the screen so the circle will move to the second point right after i tapped there! - even if the circle still moving to the first point, immediately he will start move to the second point. (and this is the hard part).
here is my code when I tap the screen:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view.layer removeAllAnimations];
UITouch *myTouch = [[touches allObjects] objectAtIndex: 0];
CGPoint currentPos = [myTouch locationInView: self.view];
[UIView animateWithDuration:2
delay:0.0f
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^(){
circle.center = CGPointMake(currentPos.x, currentPos.y);
}
completion:^(BOOL finished){}];
}
Please help me to solve that problem.. maybe there is another way to animate that circle or when tapping the screen.
even if you can give code that when I press a button so the circle just will stop and dont move right at the point that he was when i pressed the button - (even if the circle was in animation) so it will be great.. Thanks.