自动版式X $ C $ 6:需要自动版式约束这样的: [英] AutoLayout Xcode6: Need autolayout constraints for this:

查看:218
本文介绍了自动版式X $ C $ 6:需要自动版式约束这样的:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自动布局新的(我在自动尺寸调整好)。我的要求是: -


  1. 我有两个观点(比如蓝色和绿色,宽,既考虑到高度为300 iPhone5的像素)。两个视图的高度和宽度可根据屏幕分辨率改变。 X和Y原点也可以改变。


  2. 我应该使用什么约束这种自动尺寸调整掩码。



解决方案

如果蓝色和绿色是兄弟目前还不清楚或者一个包含其他。

如果你想达到的效果可以通过自动尺寸调整面具制作,那么你可以设置 translatesAutoresizingMaskIntoConstraints 为true,并自动尺寸调整面罩会自动翻译成约束。

在一般情况下,如果要安装手动约束模仿具有柔性的宽度和柔性高度的自动尺寸调整掩模的作用,那么你将被创建四种约束维护视图的边缘和之间的固定距离要这样做对应它​​的父的边缘 - 即,图的顶部和上海华的顶部,底部的底部,在左与左,右,右

这可能与像琴弦视觉语言形式来实现H:| - (10) - [查看] - (10) - |和V:| - (10) - [查看] - (10)|。这是假设没有其他冲突的约束尝试设置视图的高度和宽度。

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.

解决方案

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.

这篇关于自动版式X $ C $ 6:需要自动版式约束这样的:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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