您可以在 iPhone 中使用 Quartz 制作渐变动画吗?

发布于 2024-08-13 03:40:08 字数 262 浏览 3 评论 0原文

我是 iPhone 开发新手,目前正在尝试重新创建我为 Silverlight 开发的图表工具。

目前,我正在使用渐变来“填充”代表图表中条形的矩形。是否可以为该渐变设置动画,以便当用户触摸图表中的条形时它会改变颜色。

我已经浏览了 Apple 提供的核心动画指南,但看不到针对渐变的属性。我想我可以使用过渡在两个矩形之间淡入淡出,其中一个具有我的起始渐变,第二个具有“触摸”版本,但这显然意味着为每个条绘制多个矩形对象,我假设有额外的性能开销。

有什么想法吗?

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

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.

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.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧话新听 2024-08-20 03:40:08

是的,您确实可以使用 Core Animation 来制作渐变动画。

3.0 中出现的 CAGradientLayer 类有一个很好的 API,用于将渐变渲染到图层中,以及对颜色和颜色停止变化进行动画处理。

我不久前在这门课上发表了一篇文章以及底部链接的一些示例代码。

在示例中,我通过构建 CABasicAnimation 来对渐变进行动画处理,但您也可以通过将新的颜色数组传递到渐变层的颜色属性来隐式对更改进行动画处理。使用隐式动画,除非有理由不这样做。

检查一下,如果您对要设置动画的 UI 有任何特定问题,请告诉我。

Yes, indeed you can animated gradients with Core Animation.

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.

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

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文