2012-05-10 2 views
1

私はBezierPath on Touchイベントを描画しています。ジェスチャメソッドを使用して同じ位置でそのベジェパスを回転させる必要があります。しかし問題は、回転後にその位置が変化することです。その画像は次のようなものです。どうすればこの問題を解決できますか?UIViewでのBezierPathローテーション

BezierPath Drawing

上部画像は原画像です。 はApple documentation.

applyTransform: に...私と一緒に事前に おかげ

答えて

1

チェックこれをあなたのアイデアを共有し、指定アフィン変換行列を使用して、パス内のすべてのポイントを変換します。

- (void)applyTransform:(CGAffineTransform)transform 

私はこれを試しませんでした。しかし、ここにNSBezierPathをリンクrotating-nsbezierpath-objectsからローテーションする方法があります。 UIBezierPathで同様のアプローチを使用してください。

- (NSBezierPath*)rotatedPath:(CGFloat)angle aboutPoint:(NSPoint)cp 
{ 
// return a rotated copy of the receiver. The origin is taken as point <cp> relative to the original path. 
// angle is a value in radians 

if(angle == 0.0) 
    return self; 
else 
{ 
    NSBezierPath* copy = [self copy]; 

    NSAffineTransform* xfm = RotationTransform(angle, cp); 
    [copy transformUsingAffineTransform:xfm]; 

    return [copy autorelease]; 
} 
} 

使用する:

NSAffineTransform *RotationTransform(const CGFloat angle, const NSPoint cp) 
{ 
// return a transform that will cause a rotation about the point given at the angle given 

NSAffineTransform* xfm = [NSAffineTransform transform]; 
[xfm translateXBy:cp.x yBy:cp.y]; 
[xfm rotateByRadians:angle]; 
[xfm translateXBy:-cp.x yBy:-cp.y]; 

return xfm; 
} 
関連する問題