问题描述
我有一个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!