您的位置:首页 > 其它

给定一组点画三次贝塞尔曲线

2015-07-23 08:15 337 查看
关于过已知点画平滑曲线,这里有一篇比较好理解的博客http://blog.csdn.net/microchenhong/article/details/6316332

需求是:给定一组数据,将其用平滑曲线描绘出来,画成一个曲线统计图。

我这里直接将数据根据公司需求换成了一个存放“CGPoint”的数组,直接上代码:

//根据points中的点画出曲线
- (void)drawCurveChartWithPoints:(NSMutableArray *)points
{
    UIBezierPath* path1 = [UIBezierPath bezierPath];
    [path1 setLineWidth:2];     //设置画笔宽度
    //遍历各个点,画曲线
    for(int i=0; i<[points count]-1; i++){
        CGPoint startPoint = [[points objectAtIndex:i] CGPointValue];
        CGPoint endPoint = [[points objectAtIndex:i+1] CGPointValue];
        [path1 moveToPoint:startPoint];
        [UIView animateWithDuration:.1 animations:^(){
            [path1 addCurveToPoint:endPoint controlPoint1:CGPointMake((endPoint.x-startPoint.x)/2+startPoint.x, startPoint.y) controlPoint2:CGPointMake((endPoint.x-startPoint.x)/2+startPoint.x, endPoint.y)];
        }];
    }
    [self.lineColor set];       //设置画笔颜色
    path1.lineCapStyle = kCGLineCapRound;
    [path1 strokeWithBlendMode:kCGBlendModeNormal alpha:1];
}


PS:这是我暂时找到的较好的方法了,如果有更Nice的方法,请给我留言。不胜感激。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: