如何使用UIBezierPath在touchesMoved中绘制一条线?当我尝试使用两个触摸/手指绘制一条线时,它被绘制但是它绘制了多条线。我尝试删除lastObjectIndex并尝试removeAllObjects但仍然是相同的结果。我只想从手指1到手指2绘制一条线,当用户释放他/她的手指时,该线将在UIImageView上绘制。这是我的代码:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([drawMode isEqualToString:@"stroke"]) {
UITouch *touch=[[touches allObjects] objectAtIndex:0];
[myPath addLineToPoint:[touch locationInView:self]];
}
else if ([drawMode isEqualToString:@"line"]) {
NSArray *allTouches = [touches allObjects];
if ([touches count] == 2) {
UITouch *touch1 = [allTouches objectAtIndex:0];
UITouch *touch2 = [allTouches objectAtIndex:1];
CGPoint touchLoc1 = [touch1 locationInView:self];
CGPoint touchLoc2 = [touch2 locationInView:self];
[myPath moveToPoint:touchLoc1];
[myPath addLineToPoint:touchLoc2];
[shapeArray removeAllObjects];
[shapeArray addObject:myPath];
}
}
[self setNeedsDisplay];
}