UIScrollView内容偏移问题 [英] Problem with UIScrollView Content Offset

查看:450
本文介绍了UIScrollView内容偏移问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iPad应用程序,其中我有一个滚动视图,其大小根据我显示在其中的对象数量动态确定。现在,虽然我没有设置任何内容偏移量,但我发现只要视图加载,滚动视图就会偏移一些量。当我检查偏移的值时,它显示0.我不明白为什么没有contentOffset值,scrollview就是这样的。有什么原因吗?

Im developing an iPad app in which I have a scrollview, the size of which i determine dynamically depending on the number of objects i display in it. Now, though i have not set any content offset I find that the scroll view has been offset by some amount whenever the view loads. When I check the value of the offset, it shows 0. I dont understand why without having a contentOffset value, the scrollview behaves that way. Any reasons for this?

我怀疑这与iOS 4.2有关,因为我不记得在iOS 3.2上测试应用程序时出现的这个问题。

I suspect this has something to do with iOS 4.2 as i dont remember this problem occurring when i was testing the app on iOS 3.2.

更新:它获得的偏移量似乎根据scrollView的contentSize而有所不同。如果scrollView的contentSize匹配其帧高度(它的垂直滚动视图),则没有偏移量。随着contentSize增加到scrollView框架高度的值以上,偏移量也会按比例增加。但是,scrollView.contentOffset.y仍然= 0.0

Update: The amount its getting offset seems to vary based on the contentSize of the scrollView. If the contentSize of the scrollView matches that of its frame height (its a vertical scrollview), then there is no offset. As the contentSize increases above the value of the height of the scrollView frame, the offset also increases proportionally. However, scrollView.contentOffset.y still = 0.0

推荐答案

UIScrollView在具有iOS 4.2的iPad上的行为最终不同。 1比在iOS 3中。
我还不知道这是一个错误还是我在文档中遗漏了一些关于进化的东西。

The UIScrollView definitively does not behave the same way on iPad with iOS 4.2.1 than in iOS 3. I don't yet know if it's a bug or if I missed something in the documentation about an evolution.

我的滚动视图是在xib中创建,我重复使用它来显示同一个类的不同对象。在我的代码中,我只修改了此滚动视图的contentSize。

My scrollview was created in a xib and I was reusing it to display different object of the same class. In my code, I only modified the contentSize of this scrollview.

使用NSLog查看时偏移量保持为0,但在屏幕上有所不同。

The offset remained at 0 when looking with NSLog, but was varying on screen.

为了解决我的问题,每次我显示一个新对象时,我最终都会以编程方式创建一个新的scrollview。在你的情况下可能不可能,但对我来说,问题已解决解决了。

To fix my problem, I ended up creating programmatically a new scrollview each time I was displaying a new object. Might not be possible in your case, but for me, problem solved worked around.

这篇关于UIScrollView内容偏移问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆