2012-05-10 106 views
1

我正在绘制一个BezierPath on Touch事件。现在我必须使用手势方法在相同的位置上旋转Bezier路径。但问题是,轮换后它的位置变了。它看起来像下面的图片..我该如何解决这个问题?BezierPath旋转UIView

BezierPath Drawing

在上部图像是原始图像。 跟我分享一下你的想法.. 预先感谢

回答

1

入住这Apple documentation.

applyTransform: 使用指定的仿射变换矩阵来变换所有点的路径。

- (void)applyTransform:(CGAffineTransform)transform 

我还没有试过这个。但这里是如何从链接rotating-nsbezierpath-objects旋转NSBezierPath。尝试在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; 
}