I am using the following code to generate an image which is touchable.
I read some posts here saying UIButton
cannot be used during animation so I changed to use tap gesture. I have also added the UIViewAnimationOptionAllowUserInteraction
in option. But I still cannot make it work. May I know the reason and any solution?
hit1 = [[UIImageView alloc]initWithFrame:CGRectMake(539,227,50,50)];
hit1.image=[UIImage imageNamed:@"roles.png"];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hitenermy:)];
[hit1 addGestureRecognizer:singleTap];
[hit1 setMultipleTouchEnabled:YES];
[hit1 setUserInteractionEnabled:YES];
hit1.userInteractionEnabled=YES;
[self.view addSubview:hit1];
[hit1 addGestureRecognizer:singleTap];
UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction;
[UIView animateWithDuration:15.0
delay:1.0
options:options
animations:^{
hit1.center = CGPointMake(hit1.center.x-210, hit1.center.y-60);
}
completion:^(BOOL finished){
}];