• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

如何设置运行时计算的变量高度的布局约束?(How to set layout constraints for varia ...

原作者: [db:作者] 来自: 网络 收藏 邀请

如何设置运行时计算的变量高度的布局约束?(How to set layout constraints for variable hight calculated at run time?)

我有一个带有3个UIViews的UIView作为其子视图。 我已将这些子视图的布局约束设置为固定宽高比。 即如果屏幕尺寸改变,它们的宽度将改变,但纵横比将始终相同。

现在我也使UIView的宽度(屏幕截图中显示的红色)随着屏幕尺寸的变化而变化。 但我正在努力限制这种观点的高度。 我想要的是它的高度应该根据它里面的子视图的总高度来设置。

因为如果屏幕的宽度发生变化,子视图的高度将会改变,因为我已经修正了它们的宽高比。

截至目前,我已经确定了红色超级视图的高度。 但我希望它根据其中所有子视图的总高度而变化。

这是我的viewcontroller及其预览的屏幕截图。

在此处输入图像描述

正如您所看到的那样,由于红色超视图的固定高度,因此剩余一些空间。

到目前为止我所添加的约束细节如下。

主红色SuperView

主红色SuperView

**分别为第1(上),第2(中),第3(下)子视图**

在此处输入图像描述


I have a UIView with 3 UIViews as its subviews. I have set layout constraints for these subview as fixed aspect ratio. i.e if the screen size changes their width will change but aspect ratio will always be the same.

Now i have also made width of the UIView (the red one as shown in screen shot) changing as the screen size changes. But i am struggling to make constraint for height of this view. what i want is its height should be set according to the total height of the subviews inside it.

since the height of the subviews will change if the width of the screen changes, because i have made their aspect ratios fixed.

As of right now i have made height of the Red superview fixed. but i want it to be variable according the total height of all the subviews inside it.

Here is the screen shot of my viewcontroller and its preview.

enter image description here

As you can see there is some space remaining because of the fixed height of red super view.

Details of the constraints i have added so far are as bellow.

Main Red SuperView

Main Red SuperView

**1st (Top), 2nd (Middle), 3rd (Bottom) Subviews respectively **

enter image description here


原文:https://stackoverflow.com/questions/30526275
更新时间:2022-03-21 14:03

最满意答案

在所有分辨率中支持相同的行为。 你需要设置如下布局。

红色视图 在此处输入图像描述

UIView Top

在此处输入图像描述

UIView中

在此处输入图像描述

UIView Bottom

在此处输入图像描述

希望这能帮助你。


To support same behaviour in all resolution. you need to set layout as follow.

Red View enter image description here

UIView Top

enter image description here

UIView Middle

enter image description here

UIView Bottom

enter image description here

hope this help you.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap