0

I just created a custom UITextView in which allows to insert placeholders. (Referring from Placeholder in UITextView)

However, when you use this custom UITextView, you cannot make a flashing background effect of it. * Flashing animation codes below

- (void)startFlashAnimation: (UITextView *)textView
{

[UIView animateWithDuration:3.0
                      delay:0.0f
                    options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
                 animations:^{
                     NSLog(@"Animation start");
                     //NSLog(@"Color %@", [_flashColorsArr description]);

                     NSArray *arr = @[[UIColor orangeColor], [UIColor blueColor], [UIColor greenColor]];
                     for (UIColor *color in arr) {
                         NSLog(@"color %@", color);
                         textView.backgroundColor = color;

                     }

                 }
                 completion:^(BOOL finished){
                     NSLog(@"Finished the animation!");
                 }];
}

That would be really appreciate if you make a flash animation effect in this custom UITextView.

Cheers,

Community
  • 1
  • 1
user1574429
  • 251
  • 1
  • 4
  • 14
  • 1
    So you animate to green background? – pronebird Dec 07 '14 at 02:26
  • What I want to do is to make a flash background animation which change colours among orange, blue and green repeatedly! It does make sense? Sorry for my explanation being ambiguity. – user1574429 Dec 07 '14 at 02:40

1 Answers1

1

You have to chain animations and run a sequence of animateWithDuration: one after another. Because each animation can only interpolate between two values of the same property, current or start value and end value or new.

For the starter use animateWithDuration completion block to schedule next animation and change background color to next color.

The other important thing is that Text field's background color might not be animatable which means you have to work directly with CALayer. Take a look at similar questions on SO:

How to animate the background color of a UILabel?

FYI: CoreAnimation provides more advanced tools for animations such as CAKeyframeAnimation which allows to interpolate value between multiple values in sequence.

Community
  • 1
  • 1
pronebird
  • 12,068
  • 5
  • 54
  • 82
  • Thank you for your kind tips, Andy! I so appreciate. > For the starter use animateWithDuration completion block to schedule next animation and change background color to next color. That would be great if you give me example codes for that. Of course I will research for your advices myself. Thank you again. – user1574429 Dec 07 '14 at 11:56
  • 1
    You already have code. Just set one color at time, and start next animation inside of `completion` block. – pronebird Dec 07 '14 at 12:58
  • Thank you Andy, I will try it again referred by your tips! – user1574429 Dec 07 '14 at 18:39