简体   繁体   中英

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. They were all aligned on their left edges (so that button1.frame.origin.x = button2.frame.origin.x and so on.)

Now, for update purpose, I need to rotate all 5 of them, by 9 degrees anticlockwise.

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.

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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