简体   繁体   English

使用渐变缩放UIView

[英]Scale a UIView with gradient

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. 在开始时,所有列的大小均为1,并将缩放到预定义的高度。

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. 关键是:我想在列中绘制渐变(它们是UIView的子类),并希望比例动画重新计算渐变。

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. 由于视图具有1个点的高度,因此渐变仅显示为1种颜色。

Can someone give me a north to solve this issue? 有人可以给我北方解决这个问题吗?

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. 其中scaleY之前已计算,并且是包含Y比例因子的NSNumber。 It's not necessary to set 不需要设置

 view.contentMode = UIViewContentModeRedraw;

Thank you DarkDusk for the help. 谢谢DarkDusk的帮助。

Try setting the contentMode : 尝试设置contentMode

myView.contentMode = UIViewContentModeRedraw;

This will force a redraw on every size change. 这将在每次尺寸更改时强制重画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM