开发者

Animate the change of a stroke color on UIView

开发者 https://www.devze.com 2022-12-09 20:19 出处:网络
I\'d like to \"pulse\" the stroke color on a path that I\'ve drawn in a UIView\'s drawRect. But not sure this is possible?

I'd like to "pulse" the stroke color on a path that I've drawn in a UIView's drawRect. But not sure 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'm only able to see the change if i setNeedsDisplay on the view. But that bypasses the animation. I can think of a few workarounds if this isn't possible like overlaying another semi-transparent view with the proper color and just fading it in... but for some reason I thought animating color prope开发者_高级运维rties was possible in Cocoa?!? Perhaps I'm mistaken. Hopefully one of you can set me straight.


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

In drawRect: you are essentially painting a colour when you stroke a path, those bits just get blitted to the screen. At that point, the colour isn't really a property of the view so much as part of the painting.

I wrote a UIView that pulsed this summer (emulating the "In Call" status bar) by creating two UIViews stack atop each other, and animating both of their color properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消