使用渐变缩放 UIView

发布于 2025-01-03 06:33:01 字数 219 浏览 5 评论 0原文

我正在开发一个动画柱形图,但遇到了一些麻烦。 条形图以缩放动画显示。开始时,所有列的大小均为 1 磅,并将缩放至预定义的高度。

要点是:我想在列中绘制渐变(它们是 UIView 的子类)并希望缩放动画重新计算渐变。

到目前为止,我已经绘制了渐变,但是当列缩放时,渐变不会随之缩放。 由于视图的高度为 1 点,因此渐变仅显示为 1 种颜色。

有人可以给我一个北来解决这个问题吗?

I'm developing an animated column bar chart and i having some trouble.
The bars show up with an scale animation. At the beginning all columns have 1 point size and will scale till a predefined height.

The point is: I want to draw a gradient into the columns (They are subclasses of UIView) and want the scale animation to recalculate the gradient.

Until now, i have drawn the gradient, but when the column scale, the gradient does not scale with it.
As the view have 1 point height, the gradient is show as 1 color only.

Can someone give me a north to solve this issue?

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

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

发布评论

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

评论(2

香橙ぽ 2025-01-10 06:33:01

解决了问题!

我使用比例而不是更改视图的边界..
Was

view.transform = CGAffineTransformMakeScale(1.0, scaleY.floatValue);

必须是

view.bounds = CGRectMake(view.bounds.origin.x, view.bounds.origin.y * scaleY.floatValue, view.bounds.size.width, view.bounds.size.height * scaleY.floatValue);

之前计算过的scaleY,并且是包含Y 比例因子的NSNumber。
不需要设置

 view.contentMode = UIViewContentModeRedraw;

谢谢DarkDusk的帮助。

Solved the problem!

i was using scale instead of changing the view's bounds..
Was

view.transform = CGAffineTransformMakeScale(1.0, scaleY.floatValue);

Must be

view.bounds = CGRectMake(view.bounds.origin.x, view.bounds.origin.y * scaleY.floatValue, view.bounds.size.width, view.bounds.size.height * scaleY.floatValue);

Where scaleY was calculated before and is a NSNumber that contains the Y scale factor.
It's not necessary to set

 view.contentMode = UIViewContentModeRedraw;

Thank you DarkDusk for the help.

花开浅夏 2025-01-10 06:33:01

尝试设置 contentMode

myView.contentMode = UIViewContentModeRedraw;

这将强制在每次大小更改时重绘。

Try setting the contentMode:

myView.contentMode = UIViewContentModeRedraw;

This will force a redraw on every size change.

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