Search code examples
iphonecore-animation

What is CGAffineTransformMakeRotation(RADIAN) exactly doing?


I don't really understand what this function is good for. Can someone explain that (maybe with some examples)?

Can I rotate an UIImageView object with this one?


Solution

  • CGAffineTransformMakeRotation is a constructor that creates you a rotation matrix, like CGPointMake, or NSMakePoint. Some functions requires you to pass in a transformation matrix like:

     
    void CGPathAddArc (
       CGMutablePathRef path,
       const CGAffineTransform *m,
       CGFloat x,
       CGFloat y,
       CGFloat radius,
       CGFloat startAngle,
       CGFloat endAngle,
       bool clockwise
    );
    

    You can use UIGraphicsGetCurrentContext to get a CGContextRef and transform/rotate the context as you like.

    UPDATE: You can directly change UIView's transform. It is a property:
    @property(nonatomic) CGAffineTransform transform.
    Thanks to Brad for pointing this out.