所以我已经在这个项目上工作了一段时间,它需要我旋转和翻转标签。
这是我的:
@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/