Myaaoonn
Myaaoonn

Reputation: 997

BezierPath Rotation in a UIView

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?

BezierPath Drawing

The Upper image is the original image. Share your ideas with me.. Thanks in advance

Upvotes: 2

Views: 2886

Answers (1)

iDev
iDev

Reputation: 23278

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

Upvotes: 3

Related Questions