0

如何使用 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];
}
4

0 回答 0