dickfala
dickfala

Reputation: 3306

iOS using color animation button click not work

I have a question about the iOS in Objective-c.

I try to add the background color animation .

Animation is working properly but my button action is not getting called.

How to fix that? Thank you very much.

 - (void)viewDidLoad {
      [super viewDidLoad];
      [self.view setBackgroundColor:[UIColor colorWithRed:0.89 green:0.10 blue:0.220 alpha:1.000]];
      [UIView animateKeyframesWithDuration:3.0 delay:0.0 options:UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat animations:^{
          [self.view setBackgroundColor:[UIColor colorWithRed:148/255.0 green:28/255.0 blue:81/255.0 alpha:1]];
      } completion:nil];

 }


 - (IBAction)btnPressed:(UIButton *)sender {
     NSLog(@"button click action");
 }

Upvotes: 1

Views: 57

Answers (1)

Sharad Chauhan
Sharad Chauhan

Reputation: 4891

Add UIViewKeyframeAnimationOptionAllowUserInteraction to allow user interactions during animation :

 [UIView animateKeyframesWithDuration:3.0 delay:0.0 options:UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat | UIViewKeyframeAnimationOptionAllowUserInteraction animations:^{
     [self.view setBackgroundColor:[UIColor colorWithRed:148/255.0 green:28/255.0 blue:81/255.0 alpha:1]];
 } completion:nil];

Upvotes: 1

Related Questions