I'm animating several UIIimageView's that have a tap gesture recognizer attached to them. They respond when not animating, but when I do animate, there is no response (tried this with UIButton's as well). The weird thing is that I have the AllowUserInteraction and UIViewAnimationOptionAllowAnimatedContent options included in the animation and it still doesn't work. I also enable userInteraction on the iViews and double check to see the boolean value of the viewcontroller view and the imageview's view userInteractionEnabled to make sure it is on (it is and prints out 1,1) Any ideas?
This method creates the image view's:
-(void)addFloatingButtonHeadToView:(NSString*)userID{
/* Initialize and set properties */
UIImageView *head = [[UIImageView alloc]init];
[head setBackgroundColor:[UIColor clearColor]];
[head.layer setBorderColor:[[UIColor whiteColor]CGColor]];
[head.layer setBorderWidth:3.0f];
[head setUserInteractionEnabled:YES];
head.tag = _floatingButtonHeads.count;
/* Create tap gesture and assign to imageview head */
UITapGestureRecognizer *headTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headPressed:)];
[headTap setDelegate:self];
[head addGestureRecognizer:headTap];
/* Add to array and subview, and initialize animation */
[_floatingButtonHeads addObject:head];
[self.view addSubview:head];
[self startFloating:head];
}
This method initiates the animations:
-(void)startFloating:(UIImageView*)head{
/* Print values of userInteraction enabled to make sure they are ON */
NSLog(@"%hhd %hhd",self.view.userInteractionEnabled,head.userInteractionEnabled);
/* Create random values for x axis,y axis, and animation duration */
NSUInteger randomX = arc4random_uniform(320) + 60;
NSUInteger randomY = 60 + arc4random() % ((int)self.view.frame.size.height - 60);
NSUInteger randomDuration = arc4random_uniform(4) + 2;
/* Set image view's frame according to values*/
[head setFrame:CGRectMake(randomX, randomY, 60, 60)];
/* Start Animation*/
[UIView animateWithDuration:randomDuration delay:0.0 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionAllowAnimatedContent animations:^{
[head setFrame:CGRectMake(350, head.frame.origin.y, 60, 60)];
}completion:^(BOOL finished) {
if(finished){
[self startFloating:head];
}
}];
}