2014-03-28 42 views
4

我剛開始時有一條直線,我希望用戶能夠觸摸並拖動線條使其彎曲。實際上,他們可以將線條操作爲波形。我不確定實現這一技術的最簡單方法。iOS上的UIBezierPath操作

我已經開始創建一個三維曲線的UIBezierPaths數組,並且意圖操作控制點 - 但是看起來,一旦它們被繪製出來就不可能改變UIBezierPaths的控制點?

對最簡單的技術方法的任何建議表示讚賞。

回答

2

您可以使用變量作爲控制點在drawRect中繪製一個quadCurve(一個控制點Bezier曲線),然後如下更新touchesBegan方法中的控制點。請注意,您需要如果你有多個控制點,然後一些視覺元素和額外的邏輯在touchesMoved方法中,需要用setNeedsDisplay

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    controlPoint = [[touches anyObject] locationInView:self]; 
    [self setNeedsDisplay]; 
} 

- (void)drawRect:(CGRect)rect { 

    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); 
    CGContextSetLineWidth(context, 1.0); 

    CGContextMoveToPoint(context, 0, 320); 
    CGContextAddQuadCurveToPoint(context, controlPoint.x, controlPoint.y, 320, 200); 
    CGContextStrokePath(context); 

} 

重繪... E