你可以动画在iPhone上使用石英梯度? [英] Can you animate gradients using Quartz in an iPhone?

查看:104
本文介绍了你可以动画在iPhone上使用石英梯度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新iPhone的发展,我目前与再造一个绘图工具我Silverlight的开发玩弄。

I am new to iPhone development and am currently toying with recreating a charting tool I developed for Silverlight.

目前我使用的梯度来填充的矩形重新presenting图表中的酒吧。是否有可能使它在用户触摸图表中的条形颜色动画这个渐变。

Currently I'm using a gradient to 'fill' a rectangle representing a bar within a chart. Is it possible to animate this gradient so it changes colour when a user touches the bar within the chart.

我已通过苹果公司提供的Core Animation的导游看上去却看不到它的目标梯度的属性。我想我可以用一个过渡2 rects,其中之一有我的出发梯度,并与感动版本第二,但是这将意味着很明显绘图多个矩形对象,每个酒吧,我认为额外的服务表现开销之间褪色。

I have looked through the Core Animation guides provided by Apple but cannot see a property which targets gradients. I suppose I could use a transition to fade between two rects, one of which has my starting gradient and the second with the 'touched' version but this would mean obviously drawing multiple rect objects for each bar with I assume extra performace overheads.

任何想法?

推荐答案

是的,的确可以动画渐变与核心动画。

Yes, indeed you can animated gradients with Core Animation.

在3.0走出CAGradientLayer类有呈现渐变成层和动画的颜色和颜色停止变化,以及一个很好的API。

The CAGradientLayer class that came out in 3.0 has a nice API for rendering gradients into a layer and animating color and color-stop changes as well.

我做了这个类的一个帖子一会儿回来,一些沿样品code,它的底部相连。

I did a post on this class a little while back, along with some sample code that's linked at the bottom.

在示例中,我通过构建一个CABasicAnimation动画渐变,但可以隐式动画变化,以及由刚好路过的颜色的新阵列渐变图层的颜色属性。使用隐式动画,除非你有充分的理由不这样做。

In the sample I animate the gradient by building a CABasicAnimation, but you can implicitly animate the change as well, by just passing a new array of colors to the gradient layer's colors property. Use implicit animations unless you have a reason not to.

检查出来,让我知道,如果你有具体到你想动画UI的任何问题。

Check that out and let me know if you have any questions specific to the UI you're trying to animate.

这篇关于你可以动画在iPhone上使用石英梯度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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