2

我正在绘制一个 BezierPath on Touch 事件。现在我必须使用手势方法在同一位置旋转该贝塞尔路径。但问题是,旋转后它的位置会发生变化。它看起来像下图.. 我该如何解决这个问题?

贝塞尔路径绘图

上图是原始图像。和我分享你的想法..提前谢谢

4

1 回答 1

3

在Apple 文档中检查这一点。

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

- (void)applyTransform:(CGAffineTransform)transform

我没试过这个。但这里是如何NSBezierPath从链接rotation-nsbezierpath-objects旋转 a 。尝试在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;
}
于 2012-11-02T01:12:25.007 回答