UIBezierPath在用两根手指触摸时绘制线条

时间:2013-06-13 10:44:05

标签: ios uibezierpath

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

0 个答案:

没有答案