Search code examples
iosuiviewuistoryboardcgaffinetransform

Rotate (angle) a UIView, using User Defined Runtime Attributes


Is it possible to rotate a UIView or UIImageView, say 10 or 15 degrees,

actually using User Defined Runtime Attributes?

Or can it only be done in code?

(Note .. I mention "angle" and "by degrees" for the sake of google; it can get mixed-up with the idea of "rotating" for device orientation change.)


Alternately, could you perhaps subclass UIView in such a way that, a User Defined Runtime Attribute would be exposed, which does just this? (I'm rusty :/ )


Solution

  • You can use layer.transform.rotation.z key path for UIView object.
    Value has to be set in radians:

    enter image description here

    Result:

    enter image description here

    All transformation key paths are presented in Apple documentation.