Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGAffineTransformMakeRotation around external point

are there a way for rotate UIImage around external point using CGAffineTranformMAkeRotation? tnx a lot!

like image 954
DigitalBrain_DEV Avatar asked Aug 29 '11 15:08

DigitalBrain_DEV


2 Answers

Here is a function that uses the same format as the CoreGraphics CGAffineTransform API format.

This works exactly how other "RotateAt()" APIs should work.

The operation represents the equivalent of the following specification: translate(pt.x, pt.y); rotate(angle); translate(-pt.x, -pt.y);

CGAffineTransform CGAffineTransformMakeRotationAt(CGFloat angle, CGPoint pt){
    const CGFloat fx = pt.x, fy = pt.y, fcos = cos(angle), fsin = sin(angle);
    return CGAffineTransformMake(fcos, fsin, -fsin, fcos, fx - fx * fcos + fy * fsin, fy - fx * fsin - fy * fcos);
}

Just like with CGAffineTransformMakeRotation(), angle is in radians, not degrees.

like image 189
Andy Avatar answered Sep 20 '22 22:09

Andy


Set the image view's layer's anchorPoint to something outside of (0,0) and (1,1), ie view.layer.anchorPoint = CGPointMake(2, 2).

like image 36
Dan Wesnor Avatar answered Sep 19 '22 22:09

Dan Wesnor