As you said in your question, you can get the affected point using
CGPoint point = [[[event allTouches] anyObject] locationInView:self.view];
Then check if this point is inside the coordinates of the animated UIImageview , and then stop the animation. But if you use scrollview, you cannot use this because scrollview will not return any UIView touch UIView .
When your image is animated, the best choice would be to add a UITapGestureRecogniser to the image view when you add a preview of it, like
- (void) imageSpawn:(id) sender { UIImage* image = [UIImage imageNamed:@"ae"]; UIImageView *rocket = [[UIImageView alloc] initWithImage:image]; rocket.frame = CGRectMake(-25, 200, 25, 40); [UIView animateWithDuration:5 delay:0.2f options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^(){rocket.frame=CGRectMake(345, 200, 25, 40);} completion:^(BOOL fin) { }]; [myScrollView addSubview:rocket]; UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ballTapped:)]; tapped.numberOfTapsRequired = 1; [self.rocket addGestureRecognizer:tapped]; [rocket setUserInteractionEnabled:YES]; }
And in the target function write code to stop the animation:
-(void)ballTapped:(UIGestureRecognizer *)gesture {
EDIT:
If you are trying to stop viewing the image at the affected point, you can add this to the ballTapped event:
rocket.frame = CGRectMake(location.x,location.y,25,40);
But for this you need to declare UIImageView *rocket outside this specific method, i.e. declare in your header file.
source share