关于automaticallyAdjustsScrollViewInsets

最近遇到一个问题是这样的,App一般自己都会有一个UINavigationController,顶部TableView如果有tableHeaderView如果设置起始位置是(0,0)是在导航栏的下面的,为了更好地UI希望从屏幕的(0,0)开始,就遇到了上面的这个问题,简单的看一下效果:

关于automaticallyAdjustsScrollViewInsets_第1张图片
截图1

这个时候设置automaticallyAdjustsScrollViewInsets = NO效果如下:

关于automaticallyAdjustsScrollViewInsets_第2张图片
截图2

官方文档的解释如下:

automaticallyAdjustsScrollViewInsets

Specifies whether or not the view controller should automatically adjust its scroll view insets.

@property(nonatomic, assign) BOOL automaticallyAdjustsScrollViewInsets

Discussion

Default value isYES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set toNOif you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.

Availability

Available in iOS 7.0 and later.

Declared In

UIViewController.h

简单点说就是automaticallyAdjustsScrollViewInsets根据按所在界面的status bar,navigationbar,与tabbar的高度,自动调整scrollview的 inset,设置为no,不让viewController调整,我们自己修改布局即可~

如果不需要viewController来帮我们调整scrollView的inset那么在iOS7之后我们需要控制器的viewDidLoad方法中加上:

if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0) {

self.automaticallyAdjustsScrollViewInsets = NO;

}

你可能感兴趣的:(关于automaticallyAdjustsScrollViewInsets)