问题
I am new in autolayout (I am good in autoresizing). My requirement is:-
I have 2 view (say blue and green, width and height of both view is 300 pixel in iPhone5). height and width of both view can change according to screen resolution. X and Y origin can also change.
What constraints should I use for this autoresizing masks.
回答1:
It is unclear if the blue and green are siblings or if one contains the other.
If the effect you want to achieve can be produced through an autoresizing mask, then you can set translatesAutoresizingMaskIntoConstraints
to true and the autoresizing mask will be automatically translated into constraints.
In general, if you want to install constraints manually that mimic the effect of an autoresizing mask with a flexible width and flexible height, then you would do this by creating four constraints maintaining a fixed distance between the edges of the view and the corresponding edges of its superview -- that is, the top of the view and the top of the superview, the bottom with the bottom, the left with left, and right with right.
This could be done with the visual format language with strings like "H:|-(10)-[view]-(10)-|" and "V:|-(10)-[view]-(10)|". This assumes there are no other conflicting constraints that try to set the height and width of the view.
来源:https://stackoverflow.com/questions/26881203/autolayout-xcode6-need-autolayout-constraints-for-this