AutoLayout Xcode6: Need autolayout constraints for this:

混江龙づ霸主 提交于 2020-01-04 04:40:07

问题


I am new in autolayout (I am good in autoresizing). My requirement is:-

  1. 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.

  2. 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

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