固定位置旋转UILabel [英] Rotating UILabel with Fixed Position

查看:62
本文介绍了固定位置旋转UILabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑以询问自动布局在这种情况下是否有帮助?

Editing to ask if Autolayout helps in this situation?

我如何让我的UILabel保持在屏幕上的固定位置但仍然旋转? shouldAutorotateToInterfaceOrientation返回YES并且标签旋转得很好,但是无论我如何在Xcode中设置弹簧,标签的位置都会改变.

How can I have my UILabel maintain a fixed position on screen yet still rotate? shouldAutorotateToInterfaceOrientation is returning YES and the label is rotating just fine, but no matter how I set the struts an springs in Xcode the position of the label changes.

第一张图显示了如何在情节提要中创建布局,并带有四个单独的UILabel. 第二张图片显示了风景如何出现-不是我想要的. 第三张图片显示了我希望如何看待风景,每个数字的旋转动画都以数字本身为中心.

The first image shows how I've created the layout in storyboard, with four individual UILabels. The second image shows how landscape appears -- not what I want. The third image shows how I would like landscape to look, with the rotation animation of each number centered on the number itself.

推荐答案

vrk的答案正确无误,但shouldAutorotateToInterfaceOrientation:并不是布置标签的正确方法.收到shouldAutorotateToInterfaceOrientation:时,新方向的信息尚未更新.

vrk's on the right track with his answer, but shouldAutorotateToInterfaceOrientation: is not the right method in which to lay out your labels. When you receive shouldAutorotateToInterfaceOrientation:, nothing has been updated for the new orientation yet.

您应该在willAnimateRotationToInterfaceOrientation:duration:中列出您的视图.如

You should lay out your views in willAnimateRotationToInterfaceOrientation:duration:. As the documentation states:

在调用此方法时,interfaceOrientation属性已经设置为新的方向,并且视图的边界已更改.因此,您可以使用此方法执行视图所需的任何其他布局.

By the time this method is called, the interfaceOrientation property is already set to the new orientation, and the bounds of the view have been changed. Thus, you can perform any additional layout required by your views in this method.

您甚至可以通过这种方法将视图动画到他们的新位置.

You could even animate your views to their new positions in this method.

这篇关于固定位置旋转UILabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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