简体   繁体   English

如何使用autolayout约束在一个屏幕中放置两个视图

[英]How can I place two views in a single screen using autolayout Constraints

I would like to create apps which have 2 views (top & bottom). 我想创建具有2个视图(顶部和底部)的应用程序。

The top view is scrollable and contains multiple textfields and labels. 顶视图是可滚动的,包含多个文本字段和标签。

The bottom view is non-scrollable but needs to auto adjust to fit into bottom screen like a keyboard when the screen size is changed (I want it to be usable from iPhone 4 to 6 Plus). 底部视图是不可滚动的,但需要在屏幕尺寸改变时自动调整以适应键盘的底部屏幕(我希望它可以从iPhone 4到6 Plus使用)。 The bottom view will contain a custom function button to trigger actions and updates in the top view. 底部视图将包含一个自定义功能按钮,用于在顶视图中触发操作和更新。

I have this working on Android with LinearLayout, but I'm stuck with iOS. 我使用LinearLayout在Android上工作,但我坚持使用iOS。

截图

Try to place table view or scroll view in top which will scroll and a UIView on bottom. 尝试将表格视图或滚动视图放在顶部,滚动视图和底部的UIView。 make the height of UIView constant and table view or scroll view which you will use in top will change the height according as the screen size. 使UIView的高度保持不变,您将在顶部使用的表视图或滚动视图将根据屏幕大小更改高度。 If you got confused the post the comment. 如果你对评论发布感到困惑。

For table view see this tutorial iOS - Custom table cell not full width of UITableView 对于表视图,请参阅本教程iOS - 自定义表格单元格不是UITableView的全宽度

Step1 : Place table view and view as below . 第一步:放置表格视图和视图如下。 upper part is table view and lower is view 上半部分是表视图,下部是视图

在此输入图像描述

Step2: Place the constraints for view as below 第2步:为视图放置约束,如下所示

AT first 首先

在此输入图像描述

At second 第二个

在此输入图像描述

Step 3: Place the constraints for table view as below 第3步:放置表视图的约束,如下所示

在此输入图像描述

Try and inform me what u got 试着告诉我你得到了什么

In your case I will suggest to drag all those buttons into a UIView . 在你的情况下,我建议将所有这些按钮拖到UIView Then place the buttons with the desired spacing. 然后放置所需间距的按钮。 Select all the buttons and give equal width and equal height constraint. 选择所有按钮并给出相等的宽度和相等的高度约束。 And then give spacing constraints between neighbour buttons or views. 然后在邻居按钮或视图之间给出间距约束。 And then give constraint for the UIview to the UIViewcontroller 然后将UIview的约束赋予UIViewcontroller

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Xcode Playground中使用自动布局约束显示视图? - How can I display views using autolayout constraints in Xcode playground? 使用UITableViewCell进行自动布局约束以显示两个视图 - Autolayout constraints with UITableViewCell to display two Views 使用自动布局将屏幕分为1/3和2/3视图 - Dividing screen in to 1/3 and 2/3 views using autolayout 如何使用约束将两个视图固定在一起 - How to pin two views together using constraints 如何在不使用代码的情况下使用约束自动布局来在横向和纵向上指定其他布局? - How can I use constraints AutoLayout with to specify a different layout on landscape vs. portrait without using code? 使用自动布局约束时如何获取视图的当前宽度和高度? - How can I get a view's current width and height when using autolayout constraints? 如何在不使布局不明确的情况下使用大于或等于对iOS AutoLayout约束进行编程? - How can I program iOS AutoLayout constraints using Greater Than or Equal without making the layout ambiguous? 如何设置AutoLayout约束的常量占父视图的百分比? - How can I set AutoLayout constraints' constant as a percentage of the superview? 如何使用Autolayout在我的UIScrollview上设置约束? - How can I use Autolayout to set constraints on my UIScrollview? 如何触发所有自动布局约束的更新? - How can I trigger an update to all the autolayout constraints?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM