問題描述
我有一個 UIViewController
子類作為情節提要中的場景,其中包含一個包含各種子視圖的 UIScrollView
.其中一個子視圖是一個 UIButton
,它進入另一個場景 UIViewController
子類.當我從視圖返回時(將 UIViewController
從導航控制器堆棧中彈出),我發現滾動視圖的原點發生了某種變化,盡管 contentsize
和 contentoffset
看起來是正確的.
I have a UIViewController
subclass as a scene in the storyboard that contains a UIScrollView
containing various subviews. One of the subviews is a UIButton
which segues into another scene UIViewController
subclass. When I come back from the view (pop the UIViewController
off the navigation controller stack), I find that the scroll view's origin has somehow changed, although the contentsize
and contentoffset
seem correct.
另外有趣的是,該應用程序有一個標簽欄,當我離開并返回該視圖時,滾動視圖被正確設置為偏移量為 (0, 0).
What's also interesting is that the app has a tab bar, and when I tab away and back to that view, the scroll view is set back correctly with offset at (0, 0).
這個過程基本上不涉及任何代碼,因為它幾乎都在情節提要中.由于我對使用情節提要相當陌生,因此我認為我做錯了,盡管我不知道是什么.關于那可能是什么的任何想法?也許是規模問題或限制?
There is basically no code involved in this process, as it's pretty much all in the storyboard. As I am fairly new to using the storyboard, I figure I'm doing something wrong, although I don't know what. Any ideas as to what that may be? Perhaps sizing issues or constraints?
推薦答案
其實我把那行代碼放在viewDidDisappear
中,為了讓view重新出現時記住偏移量,我加了這個前一行
Actually, I put that line of code in viewDidDisappear
, and so that it remembers the offset when the view reappears, I added this line before it
self.contentOffset = self.scrollView.contentOffset;
還有
- (void)viewDidLayoutSubviews {
self.scrollView.contentOffset = self.contentOffset;
}
這篇關于彈回 UIViewController 后 UIScrollView 的原點發生變化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!