【发布时间】:2016-12-28 12:34:36
【问题描述】:
在 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];
}
这是我想要实现的图像,假设有五个视图,我想绘制从第一个视图到第二个、第三个等的连续线......同时我想在每个视图上绘制曲线排队。
【问题讨论】:
标签: ios objective-c drawing core-graphics