我从一个类似的问题中选择了以下代码,但是我没有运气好.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"Check #1");
UITouch* touch = [touches anyObject];
self.currentPath = [UIBezierPath bezierPath];
currentPath.lineWidth = 3.0;
[currentPath moveToPoint:[touch locationInView:self.view]];
[paths addObject:self.currentPath];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
[self.currentPath addLineToPoint:[touch locationInView:self.view]];
[self.view setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
[[UIColor redColor] set];
for (UIBezierPath *path in paths) {
NSLog(@"Check #2?");
[path stroke];
}
}
Run Code Online (Sandbox Code Playgroud)
我从中获得的是我需要使用,UIBezierPath但我不知道如何让它跟随我的手指.我只想绘制一条线,在用户触摸时启动它并在它们拿起手指的地方结束它.
如何使用UIBezierPath实现此线条图?