简体   繁体   English

如何处理iOS UIViews旋转和对齐

[英]How to deal with iOS UIViews rotation and alignment

In my existing app, I had 5 of my UIView derivatives (labels and buttons) laid up horizontally, ie on 0 degrees. 在我现有的应用程序中,我有5个UIView派生元素(标签和按钮)水平放置(即0度)。 They were all aligned on their left edges (so that button1.frame.origin.x = button2.frame.origin.x and so on.) 它们都在其左边缘对齐(因此button1.frame.origin.x = button2.frame.origin.x,依此类推。)

Now, for update purpose, I need to rotate all 5 of them, by 9 degrees anticlockwise. 现在,出于更新目的,我需要将它们全部5个逆时针旋转9度。

I achieve the the rotation easily. 轻松实现旋转。 But I can't get how adjust their left edges so that they would all be aligned again after rotation. 但是我不知道如何调整它们的左边缘,以便它们在旋转后都可以重新对齐。

The requirement, in summary, is this: The first control need to remain fixed (acting as pivot point) - the 4 others need to move right in order to maintain left alignment after rotation. 总而言之,要求是这样的:第一个控件需要保持固定(作为枢轴点)-其他四个控件需要向右移动以在旋转后保持左对齐。

I tried putting incremental x value to each of the last 4 controls (keeping the pivot x fixed) but so far don't achieve exact alignment. 我尝试将递增的x值放置到最后4个控件中的每个控件上(保持枢轴x固定),但到目前为止仍未实现精确对齐。

After rotation, it looks like all of them are center aligned, instead of left aligned which I really want. 旋转后,看起来它们全部居中对齐,而不是我真正想要的左对齐。 I know what I really want, but just looking for a smarter way so that it won't be ugly like it is now. 我知道我真正想要的,但是只是寻找一种更聪明的方法,以使它不会像现在这样丑陋。

Read about layout constraints. 了解布局约束。 That will really help you in many ways. 这确实可以在很多方面为您提供帮助。 In layout constraints the concept is very simple like 在布局约束中,这个概念非常简单,例如

Control1.attribute = Control2.attribute + C Control1.attribute = Control2.attribute + C

So you can literally program each controls attributes and achieve a fine grain control. 因此,您可以从字面上编程每个控件的属性并实现精细的控件。 You can then code it such that all the controls X is same as other controls X, they are all same distance from another control etc. 然后,您可以对其进行编码,以使所有控件X与其他控件X相同,并且它们与另一个控件等的距离都相同。

You can have multiple layout constraints and the system will try to satisfy as many as possible. 您可以有多个布局约束,系统将尝试满足尽可能多的约束。

But the only thing is that this is possible in iOS 6.0. 但是唯一的是,这在iOS 6.0中是可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM