简体   繁体   English

使UITextView在UIStackView中工作

[英]Making a UITextView work inside a UIStackView

I'm trying to add some UITextViews to a UIStackView and the text views aren't showing up. 我正在尝试将一些UITextView添加到UIStackView,并且文本视图没有显示出来。 I've researched this issue and the #1 answer I found was to make UITextViews.enableScrolling set to false . 我研究了这个问题,我发现的#1答案是将UITextViews.enableScrolling设置为false However, when I do that, the text view becomes very long. 但是,当我这样做时,文本视图变得非常长。 It goes off the view controller and the UIStackView also becomes very wide and goes off beyond the edge of the view controller. 它离开了视图控制器,UIStackView也变得非常宽,超出了视图控制器的边缘。 Also (and this is true) all the other content in the UIStackView disappears. 此外(这是真的)UIStackView中的所有其他内容都消失了。 I think this is pretty strange. 我觉得这很奇怪。

This is a vertical stack view, by the way. 顺便说一下,这是一个垂直堆栈视图。 I wish I better understood why the UIStackView was behaving this way. 我希望我更好地理解为什么UIStackView以这种方式表现。 Any ideas on how to get the stack view to behave as expected would be most appreciated. 关于如何使堆栈视图按预期运行的任何想法都将是最受欢迎的。 By the way, the UITextViews are not editable and don't have to respond to user interaction. 顺便说一句,UITextViews不可编辑,不必响应用户交互。 Below is the storyboard and the stack settings. 下面是故事板和堆栈设置。

查看控制器 堆栈设置

At this point there are no constraints being used with the stack view or its contents. 此时,堆栈视图或其内容没有使用约束。 I've updated the spacing between items to be 8, but that makes no difference- I've tried all numbers 0-8 and the UITextViews don't appear with any value. 我已经将项目之间的间距更新为8,但这没有区别 - 我已经尝试了所有数字0-8并且UITextViews没有出现任何值。 Otherwise, I've basically left the UIStackView values alone. 否则,我基本上只留下了UIStackView值。

I don't have enough rep to comment, but here's what I would suggest: Within the Stack View, you can explicitly set constraints for each object in the stack view. 我没有足够的rep来评论,但这是我的建议:在Stack View中,你可以在堆栈视图中为每个对象显式设置约束。 Try setting all the height constraints & width (using pin to sides, or explicit width) so that each object knows how to be distributed. 尝试设置所有高度约束和宽度(使用引脚到边或显式宽度),以便每个对象知道如何分布。

From https://developer.apple.com/documentation/uikit/uistackview : 来自https://developer.apple.com/documentation/uikit/uistackview

For all distributions except the fillEqually distribution, the stack view uses each arranged view's intrinsicContentSize property when calculating its size along the stack's axis. 对于除fillEqually分布之外的所有分布,堆栈视图在沿堆栈轴计算其大小时使用每个排列视图的intrinsicContentSize属性。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM