如何整体旋转 UILabel [英] How to rotate UILabel as a whole
本文介绍了如何整体旋转 UILabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个代码,它应该通过 Z 轴然后通过 Y 轴旋转 UILabel 来模拟透视.这是示例代码:
I have written a code which should turn UILabel by Z axis and then by Y axis to simulate perspective. Here is the sample code:
var t: CATransform3D = CATransform3DIdentity
t = CATransform3DRotate(t, 270 * CGFloat.pi / 180, 0, 0, 1) // rotate by z axis
t = CATransform3DRotate(t, -50 * CGFloat.pi / 180, 0, 1, 0) // rotate by y axis
t.m34 = 1.0 / -500
logLabel.transform3D = t // implement sequence of rotations to label
contentView.addSubview(logLabel)
它正确地按Z轴旋转,但不按Y轴旋转.第二次旋转使标签看起来很窄.如何模拟透视?
It rotates by Z axis correctly, but it does not rotate by Y axis. The second rotation makes the label to look narrow. How to simulate perspective?
推荐答案
您必须在设置旋转之前设置 m34
.
You must set the m34
before you set the rotation.
var transform = CATransform3DIdentity
transform.m34 = -1.0 / 500.0
transform = CATransform3DRotate(transform, 65 * CGFloat.pi / 180, 1, 0, 0)
label.layer.transform = transform
结果:
旧答案:
您可能想要更改 m34
t.m34 = 1.0 / -500
这设置远"多远标签是……更多详情这里
This sets how "far" the label is... more details here
这篇关于如何整体旋转 UILabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文