ios 线条球_iOS绘制线条的使用 - osc_v2gt986j的个人空间 - OSCHINA - 中文开源技术交流社区...

//绘制曲线

- (void)drawView{

UIBezierPath*path =[UIBezierPath bezierPath];

DrawModel*firstModel =[self.dataArr firstObject];

CGPoint firstPoint=firstModel.currPoint;

[path moveToPoint:firstPoint];if (self.dataArr.count<2) {return;

}for (int i=1; i

DrawModel*seconModel =self.dataArr[i];

CGPoint secondPoint=seconModel.currPoint;//中心点

CGPoint midPoint =[self getMindPointWithFirstPoint:firstPoint secondPoint:secondPoint];//第一个点都是中心点,为了绘制两点之间有弧度

[path addQuadCurveToPoint:midPoint controlPoint:[self getControlPointWithFirstPoint:midPoint SecondPoint:firstPoint]];

[path addQuadCurveToPoint:secondPoint controlPoint:[self getControlPointWithFirstPoint:midPoint SecondPoint:secondPoint]];

firstPoint=secondPoint;

}

CAShapeLayer*layer =[CAShapeLayer layer];

layer.lineWidth= 2;

layer.strokeColor=[UIColor redColor].CGColor;

layer.fillColor=[UIColor clearColor].CGColor;

layer.path=[path CGPath];

[self.backScrollView.layer addSublayer:layer];

}//获取两点之间控制点

-(CGPoint)getControlPointWithFirstPoint:(CGPoint)firstPoint

SecondPoint:(CGPoint)secondPoint{

CGPoint controlPoint=[self getMindPointWithFirstPoint:firstPoint secondPoint:secondPoint];

CGFloat diffY= fabs(secondPoint.y -controlPoint.y);if (firstPoint.y

controlPoint.y+=diffY;else if (firstPoint.y >secondPoint.y)

controlPoint.y-=diffY;returncontrolPoint;

}//获取两点之间中心点

-(CGPoint)getMindPointWithFirstPoint:(CGPoint)firstPoint

secondPoint:(CGPoint)secondPoint{return CGPointMake((firstPoint.x + secondPoint.x)/2, (firstPoint.y + secondPoint.y)/2);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值