我需要在我的应用中显示2个条形图,我不想使用core-plot,因为过度显示2个高度可变的条形图[UIimageView with box.png]
我仅使用UIView动画进行了一些测试,这似乎足以使条形增长或缩小,[问题是高度取决于起点,所以我的条形没有Y的点0,可以改变的高度]
那么如何为Y轴设置点0?所以我只需要考虑高度,而不是起点?
还是我应该使用一些bar生成器框架,它不会像core-plot那样被杀死,
最简单,最轻的重量是多少?
power-plot
ecgraph,其他?
PS。另一点是,我需要为图表创建自定义背景,并自定义条形图,这就是为什么我将box.png用于条形图的原因]
代码...
viewDidLoad { ***
CGRect chartbackGroundImageRect = CGRectMake(150, 20, 632, 653);
UIImageView *chartbackGroundImage = [[UIImageView alloc] initWithFrame:chartbackGroundImageRect];
[chartbackGroundImage setImage:[UIImage imageNamed:@"chartArtBgnd.png"]];
chartbackGroundImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:chartbackGroundImage];
[chartbackGroundImage release];
CGRect leftBarImageRect = CGRectMake(550, 550, 81, 40);
leftBarImage = [[UIImageView alloc] initWithFrame:leftBarImageRect];
[leftBarImage setImage:[UIImage imageNamed:@"leftBar.png"]];
leftBarImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:leftBarImage];
[leftBarImage release];
***}
testBarAnimation {***
// Setup the animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2]; //animation for arrow
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationBeginsFromCurrentState:YES];
CGRect newFrame = CGRectMake(550, 300, 81, 290);
leftBarImage.frame = newFrame;
[UIView commitAnimations];
***}
非常感谢!
最佳答案
定义一个实用函数:
CGRect modifyRectByHeight(CGRect originalRect, CGFloat newHeight)
{
CGRect result = originalRect;
result.origin.y += height;
result.size.height += height;
return result;
}
然后使用如下:
leftBarImage.frame = modifyRectByHeight( leftBarImage.frame, 150);
关于objective-c - 带有动画的ios简单条形图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8998072/