UIStackView 可以滚动吗?

Is it possible for UIStackView to scroll?(UIStackView 可以滚动吗?)
本文介绍了UIStackView 可以滚动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 UIStackView 中添加了更多可以显示的视图,如何使 UIStackView 滚动?

Let's say I have added more views in UIStackView which can be displayed, how I can make the UIStackView scroll?

推荐答案

如果有人在寻找无需代码的解决方案,我在情节提要中创建了一个示例来完全做到这一点,使用自动布局.

In case anyone is looking for a solution without code, I created an example to do this completely in the storyboard, using Auto Layout.

您可以从 github 获取它.

基本上,重新创建示例(用于垂直滚动):

Basically, to recreate the example (for vertical scrolling):

  1. 创建一个UIScrollView,并设置其约束.
  2. UIScrollView
  3. 中添加一个 UIStackView
  4. 设置约束:LeadingTrailingTop &Bottom 应该等于 UIScrollView
  5. 中的那些
  6. UIStackViewUIScrollView 之间设置相等的 Width 约束.
  7. UIStackView
  8. 上设置Axis = Vertical,Alignment = Fill,Distribution = Equal Spacing,Spacing = 0
  9. UIStackView
  10. 中添加多个UIViews
  11. 运行
  1. Create a UIScrollView, and set its constraints.
  2. Add a UIStackView to the UIScrollView
  3. Set the constraints: Leading, Trailing, Top & Bottom should be equal to the ones from UIScrollView
  4. Set up an equal Width constraint between the UIStackView and UIScrollView.
  5. Set Axis = Vertical, Alignment = Fill, Distribution = Equal Spacing, and Spacing = 0 on the UIStackView
  6. Add a number of UIViews to the UIStackView
  7. Run

将步骤4中的Width换成Height,并在步骤5中设置Axis = Horizo​​ntal,得到一个水平的 UIStackView.

Exchange Width for Height in step 4, and set Axis = Horizontal in step 5, to get a horizontal UIStackView.

这篇关于UIStackView 可以滚动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)