問題描述
我有一個 UIScrollView(實際上是一個 UICollectionView,但這可能無關緊要).當它出現在 IOS 7 中時,導航控制器將其 contentInset 和 contentOffset 設置為我不想要的值.它似乎正在嘗試調整狀態欄和導航欄.我非常希望它讓他們一個人呆著.我已經通過覆蓋 contentInset 和 contentOffset 的 getter 和 setter 方法來解決這個問題,并帶有一個標志來告訴對象它是否應該接受一個集合.但是有沒有更好的方法?
I have a UIScrollView (actually a UICollectionView, but that probably doesn't matter). When it appears in IOS 7, the navigation controller sets its contentInset and contentOffset to values I don't want. It appears to be trying to adjust for the status bar and the navigation bar. I'd greatly prefer it left them alone. I've fixed this by overriding the getter and setter methods for contentInset and contentOffset, with a flag to tell the object whether or not it should accept a set. But is there a better way?
推薦答案
嘗試在主視圖控制器中設置 self.automaticallyAdjustsScrollViewInsets = NO
.
Try setting self.automaticallyAdjustsScrollViewInsets = NO
in your main view controller.
這是在 iOS 7
中引入的,因此如果您支持 iOS 6
及更低版本,您可能需要使用 iOS 版本檢查來包裝它.
This was introduced in iOS 7
so you might want to wrap that with an iOS version check, if you are supporting iOS 6
and below.
更新
如果您使用情節提要,您可以在 Interface Builder 中執行此操作,也可以為您選擇的控制器選中 'Adjust Scroll View Insets'
.
If you are using storyboards, you can do this in the Interface Builder as well as by checking 'Adjust Scroll View Insets'
for your selected controller.
這篇關于iOS 7——navigationController 正在設置我的 UIScrollView 的 contentInset 和 ContentOffset的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!