UIView中的BezierPath旋转 [英] BezierPath Rotation in a UIView
问题描述
我正在绘制一个BezierPath on Touch事件。现在我必须使用Gesture方法在同一位置旋转Bezier Path。但问题是,轮换后它的位置会发生变化。它看起来像下面的图像..我该如何解决这个问题?
I am drawing a BezierPath on Touch event. Now I have to rotate that Bezier Path on the same location using Gesture Method. But problem is, after rotation its position become change. Its look like the following image.. How can I fix this?
上图是原始图像。
与我分享您的想法..
提前致谢
The Upper image is the original image. Share your ideas with me.. Thanks in advance
推荐答案
在 Apple文档。
applyTransform:
使用指定的仿射变换矩阵转换路径中的所有点。
applyTransform:
Transforms all points in the path using the specified affine transform matrix.
- (void)applyTransform:(CGAffineTransform)transform
我没试过这个。但是这里是如何从链接中旋转 NSBezierPath
rotate-nsbezierpath-objects 。尝试在 UIBezierPath
上使用类似的方法。
I haven't tried this. But here is how to rotate a NSBezierPath
from the link rotating-nsbezierpath-objects. Try to use the similar approach on 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;
}
这篇关于UIView中的BezierPath旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!