Keep text on an image readable while rotating the image

≯℡__Kan透↙ 提交于 2019-12-02 05:55:27

问题


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

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);

回答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.



来源:https://stackoverflow.com/questions/14131844/keep-text-on-an-image-readable-while-rotating-the-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!