以下是在图表中绘制垂直线的代码。
-(void)drawRect:(CGRect)rect
{
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
UIBezierPath *breakFastValuePath = [UIBezierPath bezierPath];
[breakFastValuePath moveToPoint:CGPointMake(89, 288)];
[breakFastValuePath addLineToPoint:CGPointMake(89,288-delegate.breakFastTotalamt)];
[breakFastValuePath closePath];
[[UIColor greenColor] setStroke];
breakFastValuePath.lineWidth = 10;
[breakFastValuePath stroke];
}
如何加载从起点到终点的动画视图加载?
答案 0 :(得分:1)
您可以将strokeEnd
的动画设置为0.0到1.0,以便从开始到结束沿着路径显示该行。请查看this question (about drawing a circle in Core Animation)以供参考。
答案 1 :(得分:1)
我认为你需要采取不同的方法。 我将向您展示水平线的示例,垂直情况将非常相似。 使用普通的UIView来表示您的行,其初始帧如下:
UIView *lineView = [[UIView alloc] initWithFrame:
CGRectMake(startX,startY,1,lineThickness)];//Line starts as 1 pixel long.
//Then you need to animate this inside loadView:
[UIView animateWithDuration:1//Amount of time the animation takes.
delay:0//Amount of time after which animation starts.
options: UIViewAnimationCurveEaseOut//How the animation will behave.
animations:^{
//here you can either set a CGAffineTransform, or change your view's frame.
//Both will work just fine.
lineView = CGAffineTransformMakeScale (
scaleForX,//say 100, Now the line will be a 100 pixels long.
scaleForY//say 1, Maintain line thickness.
//direction.
//Note* you could also set the frame for a similar effect.
//view's frame.
//lineView.frame = CGRectMake(startX,startY,finalLength,lineThickness)
}
completion:^(BOOL finished){//This block is called when the animation completes.
NSLog(@"Done!");
}];