Search code examples
ipaduibuilder

Set anchor points for rotation via code?


When building a custom frame/view in iOS code, how do you set its rotation behavior?

In UIBuilder you can set the "anchor" points to determine the points of reference to move the object through rotations. How do you do this via code?


Solution

  • You'll need to include and link against QuartzCore so as to get a definition of CALayer, then you can use its anchorPoint property. E.g.

    #import <QuartzCore/QuartzCore.h>
    
    ...
    
    someView.layer.anchorPoint = CGPointMake(x, y);
    

    UIViews have CALayers, and CALayers are what the OS uses for composition. You can even work directly with CALayers if you want, but UIViews add a bunch of functionality.