ios - 如何在其左上坐标旋转 UIVIew?

标签 ios swift uiview

现有的 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/

相关文章:

iphone - Google api 方向 - 绘制路线无效

swift - Facebook 图片格式?

Imageview 在运行时更改位置 - Swift

swift - 为什么这个 UIView 会移动?

objective-c - 如何判断 UILabel 何时将被截断和/或其换行位置将更改

ios - 在不丢失自动布局约束的情况下将 View 嵌入到 super View 中

ios - XCode Fix-it 建议强制解包 bool 值?

ios - 自定义字体不再作为 'fallback' 工作

ios - 在 UICollectionViewCell 中圈出 ImageView

swift - macOS:在 NSMenu NSMenuItem 之间添加分隔线?