问题描述
我在 Interface Builder 中有一个 UIViewController
,我在 UIView
中添加了一个 UIScrollView
.它的 contentOffset
属性等于 0.0,但是当我将 UIScrollView
滚动到最底部并推送另一个视图时,contentOffset
会发生变化.
I have a UIViewController
in Interface Builder, and I add a UIScrollView
to the UIView
. It has a contentOffset
property equal to 0.0, but when I scroll the UIScrollView
to the very bottom and push another view the contentOffset
changes.
NSLog
给了我以下值:
//View just loaded
2013-09-09 16:19:27.455 my_app[24588:907] Scroll View content offset is 0.000000
//We came back from another view
2013-09-09 16:19:30.957 my_app[24588:907] Scroll View content offset is 108.000000
这种行为的原因是什么?我刚刚在 IB 中添加了一个 UIScrollView
并且在代码中什么也没做.
What's the reason of this behaviour? I've just added a UIScrollView
in IB and did nothing in code at all.
scrollView的contentHeight
大于self.view.height
.scrollView 的 frame
保持不变.
The contentHeight
of the scrollView is bigger than self.view.height
. The frame
of the scrollView stays the same.
推荐答案
查看我的回答类似的问题.
您需要在 viewWillAppear:
和 viewWillDisappear:
中适当地设置滚动视图的 contentOffset
.
You need to set the scrollview's contentOffset
appropriately in viewWillAppear:
and viewWillDisappear:
.
另外,请参阅:
这篇关于推送另一个视图后 UIScrollView contentOffset 更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!