Animate the color change of a stroke on a UIView

I would like to “pulsate” the color of the stroke in the path that I drew in the UIView drawRect. But not sure if this is possible?

- (void)highlightView { if (!isHighlighted) { [UIView beginAnimations:NULL context:nil]; [UIView setAnimationDuration:0.75]; self.strokeColor = kHighlightColor; self.strokeWidth = 2.0; [UIView commitAnimations]; self.isHighlighted = YES; } } 

I can see the change if I set NeedsDisplay to the view. But it bypasses the animation. I can come up with some workarounds if this is not possible, for example, impose another translucent look with the correct color and just fade it out ... but for some reason I thought that animated color properties are possible in Cocoa?!? Maybe I'm wrong. I hope one of you can set me straight.

+1
source share
1 answer

You can absolutely animate color properties using UIView, but it really doesn't make sense in the context you're dealing with right now.

In drawRect: you essentially draw color when you stroke the path, these bits just expand to the screen. At this point, color is not really a property of the representation as part of the picture.

I wrote a UIView that pulsed this summer (emulating the status bar “In Call”), creating two stacks of UIViews on top of each other and animating both of their color properties.

+1
source

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


All Articles