为什么带有几个按钮的基本 UIScrollView 不能滚动?
为什么带有几个按钮的基本 UIScrollView 不能滚动?
所以我所做的就是:
- 创建一个基于视图的iPhone应用程序,
- 将UIScrollView拖入主控制器xib文件中,
- 滚动视图现在作为View in IB的子视图,
- 在滚动视图的IB中,将其视图高度增加到1000
- ,向滚动视图(因此它们显示为滚动视图的子级)
- 也创建了实例变量,并且属性 IBOutlet
- 在 IB 中合成链接到滚动视图的文件所有者滚动视图出口,
- 检查以确保 IB 中的滚动视图具有属性“滚动”已启用”勾选
但在 iPhone 模拟器中完成所有这些之后,它仍然不允许我滚动视图?
Why won't basic UIScrollView with a few buttons scroll?
So all I have done is:
- Create a view based iPhone app
- drag in a UIScrollView into the main controller xib file
- the scrollview now sits as a child of View in IB
- in IB in scrollview increase it's view height up to 1000
- add some buttons to the scroll view (so they appear as children of the scroll view)
- did create the instance variable also, and property IBOutlet, synthesize
- linked in IB the File Owner scrollView outlet to the scroll view
- checked to ensure the scroll view in IB had the attribute "scrolling enabled" ticked
But still after all this in the iPhone simulator it won't let me scroll the view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能不想将滚动视图
frame.size.height
属性更改为 1000.0,而是将滚动视图contentSize.height
更改为 1000.0。You probably don't want to change your scrollviews
frame.size.height
property to 1000.0, but your scrollviewscontentSize.height
.不,正确的答案是:
我在下一个链接上找到的原始答案:
UIScrollView 不会滚动(故事板)->找到 Evana 的答案
我浪费了很多时间尝试实现滚动(并且反复)。我什至使用了 2 个视图(第一个视图中的 UIScrollView 和 UIView),
这是没有必要的!
关键是: viewDidLayoutSubviews
在故事板中,您可以像任何其他元素一样实现 UIScrollView,
但关键是方法 viewDidLayoutSubviews 中的 setContentSize
No, the correct answer is:
The original answer I founded on next link:
UIScrollView won't scroll (Storyboards) -> Find Evana's answer
I waste a lot of time trying implement scroll (and repeatedly). I have even used 2 views (UIScrollView and UIView inside the first)
It is not necessary!
THE KEY IS: viewDidLayoutSubviews
In the storyboard you implement UIScrollView as any other element,
but the key is setContentSize in method viewDidLayoutSubviews
您只需要做一件事:将滚动视图上的
contentSize
属性设置为适当的值:其中
bottommostSubview
是连接到最接近的滚动视图的子视图的插座到底部。您还可以编写一个方法来自动查找此视图,或者如果您知道大小永远不会改变,则只需硬编码一个值。默认的
contentSize
为CGSizeZero
,它可以有效地禁用滚动。Only one more thing you have to do: set the
contentSize
property on your scroll view to an appropriate value:Where
bottommostSubview
is an outlet connected to the subview of the scrollview that’s closest to the bottom. You could also write a method to find this view automatically, or just hard-code a value if you know the size will never change.The default
contentSize
isCGSizeZero
which effectively disables scrolling.