在UIView上动画笔触颜色的变化 [英] Animate the change of a stroke color on UIView

查看:57
本文介绍了在UIView上动画笔触颜色的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在UIView的drawRect中绘制的路径上画出笔触颜色。但是不确定这可能吗?

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;
    }
}

只有当我setNeedsDisplay在视图上。但这绕过了动画。我可以想到一些解决方法,例如用适当的颜色覆盖另一个半透明视图并使其褪色...但是出于某种原因,我认为可以动画设置颜色属性 在可可中?!?也许我弄错了。

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 properties was possible in Cocoa?!? Perhaps I'm mistaken. Hopefully one of you can set me straight.

推荐答案

您绝对可以使用UIView设置颜色属性的动画,但这并不能真正使我眼前一亮。

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

drawRect:中,您实际上是在绘画一种颜色,当您描画路径时,这些位只会在屏幕上变白。那时,颜色实际上并不是视图的属性,而是绘画的一部分。

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.

我写了一个UIView,它在今年夏天出现了脉动(模仿在通话状态栏中),方法是在彼此顶部创建两个UIView堆栈,并对它们的 color 属性进行动画处理。

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.

这篇关于在UIView上动画笔触颜色的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆