繁体   English   中英

为图表的UIImageView设置动画

[英]animating a UIImageView for a chart

我试图从UIImageView创建一个简单的条形图,到目前为止我的代码是:

- (void)createNewBarWithValue:(float)percent andImage:(UIImageView *)newBar
{
    CABasicAnimation *scaleToValue = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
    scaleToValue.toValue = [NSNumber numberWithFloat:percent*2.5];
    scaleToValue.fromValue = [NSNumber numberWithFloat:0];
    scaleToValue.duration = 1.5f;
    scaleToValue.delegate = self;

    newBar.layer.anchorPoint = CGPointMake(0.5, 1);

    [newBar.layer addAnimation:scaleToValue forKey:@"scaleUp"];
    CGAffineTransform scaleTo = CGAffineTransformMakeScale( 1.0f, percent * 2.5);
    newBar.transform = scaleTo;
}

我在这里所做的一切非常简单,只需使用转换即可获得动画。 动画的结果可以在这里看到。

现在我要做的实际上是使我的最终图表如下:

在此处输入图片说明

现在,我在这里看到的一个问题是顶部的圆角边框。 我目前无法使用此功能。 那么最简单的解决方法是什么?

尝试这个:

newBar.layer.cornerRadius = 5;//or any other value

不幸的是,这将设置所有四个角的半径。 您可能必须隐藏底部的两个角并相应地调整高度,或者在newBar底部的顶部添加另一个图像视图。

暂无
暂无

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

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