Rotate UIView around its center keeping its size

前端 未结 10 1120
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 14:17

I\'m trying to rotate an UIView a few radians but after applying the transformation it doesn\'t look to be keeping its size. What\'s the proper way to achieve t

10条回答
  •  一整个雨季
    2020-12-02 14:43

    On Swift 3:

    let degrees: CGFloat = -90
    let radians = CGFloat(__sinpi(degrees.native/180.0))
    view.transform = CGAffineTransform(rotationAngle: radians)
    

    I'm using -90 because of this specific part of the documentation about the rotationAngle you have to pass to CGAffineTransform:

    The angle, in radians, by which this matrix rotates the coordinate system axes. In iOS, a positive value specifies counterclockwise rotation and a negative value specifies clockwise rotation.

提交回复
热议问题