现有的 CGAffineTransform 可以很好地完成这项工作,但它只会在其中心点旋转。我想在其左上角坐标中旋转 UIView,
旋转代码:
// here rectangle is UIView
rectangle.transform = CGAffineTransform(rotationAngle: 90.degreesToRadians)
扩展名:
// use to convert degree to radian
extension BinaryInteger {
var degreesToRadians: CGFloat { return CGFloat(Int(self)) * .pi / 180 }
}
我无法在建议的问题中找到答案。
最佳答案
只需在变换前更改层的 anchor 即可。例如:
rectangle.layer.anchorPoint = CGPoint.zero
rectangle.transform = CGAffineTransform(rotationAngle: 90.degreesToRadians)
关于ios - 如何在其左上坐标旋转 UIVIew?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48060394/