2012-01-25 105 views
0

我需要显示2条线图在我的应用程序,我不想使用核心情节一样是矫枉过正,只显示2变种的高度吧,[UIImageView的与box.png]IOS简单的条形图动画

我已经做了一些测试,只是使用UIView动画,这似乎足以使酒吧成长或缩小,[问题是高度取决于起点,所以我的酒吧没有0点为Y,至极随着酒吧的高度变化]

所以我怎么能为我的Y轴设置点0,所以我只需要考虑高度,而不是起点呢?

或应我去一些酒吧发电机框架,也不是那么超必杀为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]; 
***} 

非常感谢!

+0

显示你的代码,它是理解代码比解释更容易。 – ikuramedia

+0

@ikuragames嗨,请检查编辑的问题上的代码谢谢! – MaKo

+0

@MaKo:为什么不创建一个简单的'UIView'子类,为您的图形绘制可变形状的块?您可以使用Core Animation动画化内容。 –

回答

1

定义一个效用函数:

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); 
1

我不知道,它适用于您的项目。但我使用了不同的方法,因为iOS没有Chart的好库。

我在Web上使用了基于HTML5/CSS的免费图表引擎的UIWebview。对我来说,它的做工精细,有点慢比本地的图表会,但足以让我的项目