問題描述
我在 Interface Builder 中有一個(gè) UIViewController
,我在 UIView
中添加了一個(gè) UIScrollView
.它的 contentOffset
屬性等于 0.0,但是當(dāng)我將 UIScrollView
滾動(dòng)到最底部并推送另一個(gè)視圖時(shí),contentOffset
會(huì)發(fā)生變化.
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 中添加了一個(gè) 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:
中適當(dāng)?shù)卦O(shè)置滾動(dòng)視圖的 contentOffset
.
You need to set the scrollview's contentOffset
appropriately in viewWillAppear:
and viewWillDisappear:
.
另外,請參閱:
- 這個(gè)答案問題UIScrollView 彈回 UIViewController 后原點(diǎn)發(fā)生變化.
- 這個(gè)相關(guān)問題,UIScrollview 自動(dòng)布局問題.
這篇關(guān)于推送另一個(gè)視圖后 UIScrollView contentOffset 更改的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!