Rotate UIView around its center keeping its size

前端 未结 10 1161
没有蜡笔的小新
没有蜡笔的小新 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:52

    Swift 5:

    extension UIView {
        func setTransformRotation(toDegrees angleInDegrees: CGFloat) {
            let angleInRadians = angleInDegrees / 180.0 * CGFloat.pi
            let rotation = self.transform.rotated(by: angleInRadians)
            self.transform = rotation
        }
    }
    

提交回复
热议问题