【发布时间】:2012-05-10 12:17:16
【问题描述】:
我正在绘制 BezierPath on Touch 事件。现在我必须使用手势方法在同一位置旋转该贝塞尔路径。但问题是,旋转后它的位置会发生变化。它看起来像下图......我该如何解决这个问题?
上图为原图。 和我分享你的想法。。 提前致谢
【问题讨论】:
标签: iphone ios uigesturerecognizer bezier uibezierpath
我正在绘制 BezierPath on Touch 事件。现在我必须使用手势方法在同一位置旋转该贝塞尔路径。但问题是,旋转后它的位置会发生变化。它看起来像下图......我该如何解决这个问题?
上图为原图。 和我分享你的想法。。 提前致谢
【问题讨论】:
标签: iphone ios uigesturerecognizer bezier uibezierpath
在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;
}
【讨论】: