ios - 如何同时翻转和旋转标签?

标签 ios swift uikit cgaffinetransform

所以我已经在这个项目上工作了一段时间,它需要我旋转和翻转标签。

这是我的:

@IBAction func Flip(_ sender: Any) {
    UIView.animate(withDuration: 2.0,animations: {
        self.timeLabel.transform = CGAffineTransform(scaleX: -1, y: 1)
        self.timeLabel.transform = CGAffineTransform(rotationAngle: (-90 * .pi / 180.0)

我希望标签翻转(镜像),然后在点击“翻转”按钮时旋转,但模拟器中的结果只是旋转,而不是翻转。

如果有人可以为我重写这段代码,这样它就可以做到这两点,那就太好了。我是个新手,看来这个项目需要一段时间。

最佳答案

正如@rmaddy所建议的,分别准备两个转换,将它们连接在一起,最终创建一个转换,然后分配它看起来像

let flipping = CGAffineTransform(scaleX: -1, y: 1)
let rotating = CGAffineTransform(rotationAngle: (-90 * .pi / 180.0)
let fullTransformation = flipping.concatenating(rotating)
self.timeLabel.transform = fullTransformation

有关连接的更多信息,请查看以下文档 https://developer.apple.com/documentation/coregraphics/cgaffinetransform/1455996-concatenating

关于ios - 如何同时翻转和旋转标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55203214/

相关文章:

swift - 在 Swift 中检查空字符串?

swift - 拓扑排序 Swift

ios - 如何绑定(bind) SwiftUI 和 UIViewController 行为

uitableview - ios 14 Uitableviewcell 与 textField 不工作

ios - 即使应用程序不在后台也能获取实时位置更新(iPhone)

ios - CALayer 未在 View 中正确定位

ios - UIView 在设置宽度等于 scrollview 时忽略了我的约束?

ios - iOS "mobile web app"中的 location.reload(true) 在 safari 中重新打开

swift - 如何通过单击按钮在 map 上标记位置

ios - 如何使用 swift 和 UIkit 创建逼真的悬崖坠落球