BezierPath Rotation in a UIView

丶灬走出姿态 提交于 2019-12-09 13:53:16

问题


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


回答1:


Check this in Apple documentation.

applyTransform: Transforms all points in the path using the specified affine transform matrix.

- (void)applyTransform:(CGAffineTransform)transform

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];
}
}

which uses:

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;
}


来源:https://stackoverflow.com/questions/10533793/bezierpath-rotation-in-a-uiview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!