如何水平翻转UILabel?

时间:2021-05-30 17:10:31

I want to develop an iPhone application using the utility template, where the flip side is semi-transparent displaying the contents of the main view, flipped horizontally.

我想使用实用程序模板开发一个iPhone应用程序,其中反面是半透明的,显示主视图的内容,水平翻转。

Edit: To create the illusion of semi-transparent flip side, I'd display the same content on the flip view as in the main view, but mirror the content and lower the alpha.

编辑:为了创建半透明翻转侧的错觉,我会在翻转视图中显示与主视图中相同的内容,但镜像内容并降低alpha。

Is it possible to display a text using an UILabel, but mirror the text, ie flip it horizontally? Apple dev pages does not give me any help in this issue.

是否可以使用UILabel显示文本,但镜像文本,即水平翻转? Apple开发页面在这个问题上没有给我任何帮助。

2 个解决方案

#1


As August said, I'm not sure of your use case on this, but there's a reasonably straightforward way to do it using Core Animation. First, you'll need to add the QuartzCore framework to your project and do a

正如八月所说,我不确定你的用例,但是使用Core Animation有一个相当简单的方法。首先,您需要将QuartzCore框架添加到项目中并执行

#import <QuartzCore/QuartzCore.h>

somewhere in your headers.

在你的标题中的某个地方。

Then, you can apply a rotational transform to your UILabel's underlying layer using the following:

然后,您可以使用以下方法将旋转变换应用于UILabel的基础图层:

yourLabel.layer.transform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f);

which will rotate the label's CALayer by 180 degrees (pi radians) about the Y axis, producing the mirror effect you're looking for.

它将标签的CALayer绕Y轴旋转180度(π弧度),产生您正在寻找的镜面效果。

#2


In the Utility template, the flipside isn't shown semi-transparent. This is most likely for performance reasons on the iPhone. I'm not sure there's any value to having your label flipped if it's not providing any functionality.

在Utility模板中,反面未显示为半透明。这很可能是出于iPhone的性能原因。如果没有提供任何功能,我不确定你的标签是否有任何价值。

That said, I'd look into UIView's transform property.

那就是说,我会研究UIView的转换属性。

#1


As August said, I'm not sure of your use case on this, but there's a reasonably straightforward way to do it using Core Animation. First, you'll need to add the QuartzCore framework to your project and do a

正如八月所说,我不确定你的用例,但是使用Core Animation有一个相当简单的方法。首先,您需要将QuartzCore框架添加到项目中并执行

#import <QuartzCore/QuartzCore.h>

somewhere in your headers.

在你的标题中的某个地方。

Then, you can apply a rotational transform to your UILabel's underlying layer using the following:

然后,您可以使用以下方法将旋转变换应用于UILabel的基础图层:

yourLabel.layer.transform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f);

which will rotate the label's CALayer by 180 degrees (pi radians) about the Y axis, producing the mirror effect you're looking for.

它将标签的CALayer绕Y轴旋转180度(π弧度),产生您正在寻找的镜面效果。

#2


In the Utility template, the flipside isn't shown semi-transparent. This is most likely for performance reasons on the iPhone. I'm not sure there's any value to having your label flipped if it's not providing any functionality.

在Utility模板中,反面未显示为半透明。这很可能是出于iPhone的性能原因。如果没有提供任何功能,我不确定你的标签是否有任何价值。

That said, I'd look into UIView's transform property.

那就是说,我会研究UIView的转换属性。