How do you use auto layout in a scroll view?(如何在滚动视图中使用自动布局?)
问题描述
所以我在最新 Xcode 的视图控制器中使用了 UIScrollView
.我在滚动视图中有按钮.当我运行应用程序时,滚动视图消失了.谁能告诉我是什么原因造成的以及自动布局工具是如何工作的?
So I'm using a UIScrollView
in a view controller in the latest Xcode. I have buttons inside the scroll view. When I run the application, the scroll view disappears. Can anyone tell me what is causing this and how the auto layout tools work?
推荐答案
按照这些步骤,
获取滚动视图并相对于父视图设置约束(前导、尾随、顶部、底部).并为其设置一些背景颜色,使其在运行时可见.
Take scroll view and set constraints (leading, trailing, top, bottom) with respect to the parent view. And set some background color to it so that it will visible at run time.
将 UIButton 放在滚动视图上,然后设置按钮(前导、尾随、顶部)相对于滚动视图的约束,并设置按钮的宽度和高度约束,以及一些背景按钮的颜色,以便在运行时可见.
Take UIButton and place it over scrollview, and then set constraints for your button (leading, trailing, top) with respect to the scroll view, and also set the width and height constraints for button ,and also some background color to button so that it will visible at runtime.
注意:你的内容的层次应该是这样的——-父视图-滚动视图-按钮
Note: The hirearchy of your contents should be like this- -parentView -ScrollView -button
如果有什么不清楚的地方请告诉我.
please let me know if anything is not clear.
谢谢.
这篇关于如何在滚动视图中使用自动布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在滚动视图中使用自动布局?


- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01