我是新来的iOS和目标c,我正在开发一个应用程序,我想绘制连续的曲线,如下图所示。这里是我的代码,但它仅绘制单staright线..如何在核心图形中连续绘制曲线ios
- (void)drawRect:(CGRect)rect{
CGContextRef context = UIGraphicsGetCurrentContext();
// set the line properties
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, 30);
CGContextSetAlpha(context, 0.6);
// draw the line
CGContextMoveToPoint(context, startPoint.x, startPoint.y);
CGContextAddLineToPoint(context, endPoint.x, endPoint.y);
CGContextStrokePath(context);
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint current = [touch locationInView:self];
startPoint=current;
arrPoints=[[NSMutableArray alloc]init];
[arrPoints addObject:NSStringFromCGPoint(startPoint)];
}
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
endPoint=p;
[arrPoints addObject:NSStringFromCGPoint(endPoint)];
[self setNeedsDisplay];
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self touchesMoved:touches withEvent:event];
}
这里就是我想实现是假设有五种观看图片,我想继续画线从开始首先以第二,第三,等等,并在同一时间,我想在每行以绘制曲线..
我想实现的是假设有五个视图,我开始从一个视图进行绘制,并将线移动到另一个视图,在第二个视图中,我想绘制手指在哪个方向移动的曲线 – IMakk
根据您的描述, Erica Sadun的“核心iOS开发者的食谱”在配方“平滑图画”中正是你想要的。它使用称为Catmull-Rom样条的技术,从用户用手指画出的点创建平滑曲线。我建议买这本书。它充满了像那样的宝石,而且一本“配方”是值得本书的价格,因为它完全符合你的要求。 –
感谢您的回复。 – IMakk