1

我有一个 UIScrollView,里面有一个 View。该视图的内部是一堆按钮、标签等,它们在纵向模式下适合视图......当 iPad 旋转时,我希望滚动视图启动,以便用户可以滚动到视图的底部。该应用程序运行,但是当我旋转它时,滚动条永远不会工作......我相信我已经正确连接了所有东西,并且我在 viewDidLoad 事件中有这个代码:

[scrollview addSubview: masterView]; 
scrollView.contentSize = [masterView sizeThatFits:CGSizeZero]; 

还有什么我想念的吗?iPad旋转时需要修改尺寸吗?

谢谢

4

3 回答 3

1

的内容大小可能有问题UIScrollView。如果没有将 contentSize 设置为大于实际的 scrollView 大小,则不会显示滚动条。

您可以使用以下代码对此进行编码:

[scrollView setContentSize:CGSizeMake(2000,2000)];

然后将内容大小更改为您放入UIScrollView( scrollView) 中的实际内容大小。

于 2012-04-21T01:49:25.447 回答
0

我遇到了类似的情况,但我的案例是 iPhone。

请记住,内容应该大于滚动才能启动滚动视图。

“如果一切都在你面前,你为什么要下去?”

使用以下代码:

  [scrollView setContentSize:CGSizeMake(intValue, intValue)];

intValue:设置滚动宽度和高度的整数值。

即使它不起作用,也不要担心有很多其他选项可以找出解决方案:1. NSLog 2. 断点 3. 将你从控制台收到的错误放在 stackoverflow

于 2012-04-21T05:10:12.247 回答
0

If you look at the results of [masterView sizeThatFits:CGSizeZero] (e.g. NSLog or set a breakpoint in your debugger, I think you will find that it's not what you expected it to be. You might find that masterView has autoResize parameters set (which is common for a view that covers the entire screen), which means that it might, itself, be getting resized too short to fit all of its controls and scrollView is simply grabbing this shortened value itself. Take a look at that CGSize and the problem will be obvious.

于 2012-04-21T01:57:29.383 回答