How to make gesturerecognizer work in UIImage animation view

I have 5 animated images in the image view and you want to allow the user to click on them base by default identifier and click on another view. I tried adding in gestures, but the image does not detect.

Can anyone advise me?

EDIT: I ended up not using it; instead, I install UIButton.

Thank you:)

viewDidLoad

self.defaultID = [[NSMutableArray alloc] initWithObjects:@"7",@"9",@"11",@"27",@"6",nil]; self.defaultImageCaption = [[NSMutableArray alloc] initWithObjects:@"Ver",@"Green",@"Red",@"CF",@"Dwarf",nil]; //default image imageViewTop.alpha = 1.0; imageViewBottom.alpha = 0.0; imageViewBottom = [[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,367)]; imageViewTop = [[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,367)]; singleDefaultTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDefaultTap:)]; singleDefaultTap.numberOfTouchesRequired = 1; imageViewTop.userInteractionEnabled = YES; [imageViewTop addGestureRecognizer:singleDefaultTap]; imageViewTop.tag = 2000; UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0,44,320,367)]; [topView addSubview:imageViewTop]; [self.view addSubview:imageViewTop]; [self.view addSubview:topView]; [self.view addSubview:imageViewBottom]; [self nextAnimation] 

 -(void)nextAnimation{ //picture loop imageViewTop.image = imageViewBottom.image; imageViewBottom.image = [imageArray objectAtIndex:[imageArray count] - 1]; [imageArray insertObject:imageViewBottom.image atIndex:0]; [imageArray removeLastObject]; imageViewTop.alpha = 1.0; imageViewBottom.alpha = 0.0; [UIView animateWithDuration:4.0 animations:^{ imageViewTop.alpha = 0.0; imageViewBottom.alpha = 1.0; } completion:^(BOOL completed){ [self nextAnimation:stringsize.width]; } ]; 

Act

// show your warning ...

 NSLog(@"tapped"); flowerDetails = [[FlowerDetailViewController alloc] initWithNibName:@"FlowerDetailViewController" bundle:Nil] ; Fr *fr = nil; 

// click on the detailed view of the flower

+4
source share
3 answers

Precisely because when applying animation, modifying any sprite value (UIImageView in your case) using animation does not apply to the original sprite, it applies to its .layer.presentationLayer, the real one is still in its original place. In this case, you can try the following: place your gesture on the whole screen, when the response comes from the event, you check the touch point, do hitTest on the presentation layer, if so, do what you want.

I usually use the code below for this.

 - ( BOOL ) areYouThere: ( CGPoint ) point { return ( [ ( ( CALayer * )sprite.layer.presentationLayer ) hitTest: point ] != nil ); } 

Get touch point from UITouch object when calling a method

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 
+3
source

I would add a transparent view on top of the image view and add a gesture recognizer to it.

+5
source

Really late, but I ran into the same problem and I found what I consider to be the best solution:

Just use the UIViewAnimationOptionAllowUserInteraction parameter as follows:

 [UIView animateWithDuration:4.0 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ imageViewTop.alpha = 0.0; imageViewBottom.alpha = 1.0; } completion:^(BOOL completed){ [self nextAnimation:stringsize.width]; } ]; 
+1
source

Source: https://habr.com/ru/post/896809/


All Articles