旋转图像时使图像上的文本可读 [英] Keep text on an image readable while rotating the image

查看:98
本文介绍了旋转图像时使图像上的文本可读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像轮子的图像视图.该视图检测每个彩色部分上的触摸事件.

I have an image view that looks like a wheel. This view detects touch events on each of the colored sections.

我的问题是,当我旋转此轮时,还需要旋转视图顶部的UILabel,以使文本仍然水平且易于阅读.

The problem I have is that when I rotate this wheel, the UILabels on top of the view need to also be rotated so that the text is still horizontal and human readable.

旋转父视图时旋转标签的最佳方法是什么?

What is the best way to rotate the labels while the parent view is being rotated?

这就是我现在正在尝试的方法,它无法正确旋转...

This is what I am trying now and it does not rotate correctly...

CGAffineTransform textTransform = CGAffineTransformRotate(newTransform, newAngle * -1);

推荐答案

大概是在应用旋转变换来旋转轮子.如果标签是转盘视图的子视图,则其中心会固定在转盘的正确位置(因为视图位于其中心的视图中是其中心),并且它们会随其一起移动.同时,将反向旋转变换应用于标签.旋转围绕每个标签的中心进行.因此,每个标签都留在正确的位置并保持直立.

Presumably you are applying a rotation transform to rotate the wheel. If the labels are subviews of the wheel view, their centers are pinned in the right places to the wheel (because a view is located in its superview by its center), and they will travel around with it. At the same time, apply the inverse rotation transform to the labels. The rotation takes place around the center of each label. So each label stays in the right place and stays upright.

事后的想法-还请确保您没有在这些标签上使用自动版式.自动布局会中断视图转换.

An afterthought - also make sure you're not using autolayout on these labels. Autolayout breaks view transforms.

这篇关于旋转图像时使图像上的文本可读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆