UIScrollView contentOffset在推送另一个视图之后更改 [英] UIScrollView contentOffset change after another view pushed
问题描述
我在Interface Builder中有一个 UIViewController
,并且在中添加了一个
。它具有等于0.0的 UIScrollView
UIView contentOffset
属性,但是当我将 UIScrollView
滚动到底部并推动另一个视图 contentOffset
更改。
NSLog
:
//查看刚刚加载的
2013-09-09 16:19:27.455 my_app [24588:907]滚动视图内容偏移量为0.000000
//我们从另一个视图返回
2013-09-09 16:19:30.957 my_app [24588:907]滚动视图内容偏移量为108.000000
这种行为的原因是什么?我刚刚在IB中添加了一个 UIScrollView
,在代码中什么也没做。
scrollView的 contentHeight
大于 self.view.height
。
请参阅我的回答类似的问题。
您需要设置scrollview的 viewWillAppear:
和 viewWillDisappear:
适当地在 contentOffset
p>
另请参阅:
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
gives me the following values:
//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
What's the reason of this behaviour? I've just added a UIScrollView
in IB and did nothing in code at all.
The contentHeight
of the scrollView is bigger than self.view.height
. The frame
of the scrollView stays the same.
See my answer to a similar question.
You need to set the scrollview's contentOffset
appropriately in viewWillAppear:
and viewWillDisappear:
.
Also, see this:
- This answer to the question UIScrollView's origin changes after popping back to the UIViewController.
- This related question, UIScrollview Autolayout Issue.
这篇关于UIScrollView contentOffset在推送另一个视图之后更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!