我在 Interface Builder 中创建了一个 UIScrollView 并为其添加了子视图,但我无法让它滚动.我看过其他类似的问题,但我已经适当地设置了我的 contentSize.事实上,我什至尝试过设置非常大的 contentSize,但它没有产生任何影响.我错过了什么?注意 UIScrollView 是一个 IBOutlet:
I have created a UIScrollView and added subviews to it in Interface Builder, but I am not able to get it to scroll. I have looked at other similar questions, but I have set my contentSize appropriately. In fact, I have even tried setting incredibly large contentSize and it fails to make a difference. What am I missing? Note that the UIScrollView is an IBOutlet:
@property (strong, nonatomic) IBOutlet UIScrollView *scroll;
这是在我看来DidLoad:
This is in my viewDidLoad:
self.scroll.scrollEnabled = YES;
[self.scroll setContentSize: CGSizeMake(2400,8000)];
这是来自 Interface Builder 的屏幕截图:
Here are screenshots from Interface Builder:
这是运行时的视图,但在任何时候水平或垂直滚动的任何尝试都不起作用.
Here is the view while running, but any attempt at horizontal or vertical scrolling at any point does not work.
关闭自动布局可以,但这不是解决方案.如果你真的需要Auto Layout,那就使用它,如果你不需要它,把它关掉.但这不是此解决方案的正确解决方案.
Turning Auto Layout off works, but that's not the solution. If you really need Auto Layout, then use it, if you don't need it, turn it off. But that is not the correct fix for this solution.
UIScrollView
与自动布局中的其他视图不同.这是 Apple 的关于 Auto 的发行说明布局,我复制了有趣的部分(强调我的,在第三个要点):
UIScrollView
works differently with other views in Auto Layout. Here is Apple's release note on Auto Layout, I've copied the interesting bit (emphasis mine, at third bullet point):
以下是有关 UIScrollView 的自动布局支持的一些说明:
Here are some notes regarding Auto Layout support for UIScrollView:
Apple 然后继续展示如何正确使用 UIScrollView
和 Auto Layout 的示例.
Apple then goes on to show example of how to correctly use UIScrollView
with Auto Layout.
作为一般规则,最简单的解决方法之一是在元素到 UIScrollView 底部之间创建一个约束.因此,在您希望位于 UIScrollView 底部的元素中,创建此底部空间约束:
As a general rule, one of the easiest fix is to create a constraint between the element to the bottom of the UIScrollView. So in the element that you want to be at the bottom of the UIScrollView, create this bottom space constraint:
再一次,如果您不想使用自动布局,请将其关闭.然后,您可以按通常的方式设置 contentSize
.但你应该明白,这是 Auto Layout 的预期行为.
Once again, if you do not want to use Auto Layout, then turn it off. You can then set the contentSize
the usual way. But what you should understand is that this is an intended behaviour of Auto Layout.
这篇关于无论内容大小如何,UIScrollView 都不会滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!