UIViewController的automaticAdjustsScrollViewInsets如何工作?

时间:2013-10-08 11:04:05

标签: objective-c xcode5

self.automaticallyAdjustsScrollViewInsets = YES;

我把它设为是。我认为默认是肯定的。

然后,当我检查插图时,这就是我得到的: NSStringFromUIEdgeInsets(self.tableView.contentInset):{0,0,0,0}

我认为它应该以包含navigationBar和statusbar的方式设置。那发生了什么?

2 个答案:

答案 0 :(得分:5)

据我所知

automaticallyAdjustsScrollViewInsets

  

允许视图控制器调整其滚动视图插入   响应状态栏,导航所消耗的屏幕区域   栏,工具栏或标签栏

  • 适用于视图,该视图是View Controller视图的直接子视图(someone says it must be the first subview
  • 此视图必须是ScrollView子类
  • View Controller嵌入在Navigation Controller或TabBar中 控制器
  • edgesForExtendedLayoutUIEdgeRectTop(如果您需要ScrollView 子类视图在顶部栏后面),UIEdgeRectBottom(如果你想要的话) ScrollView子类视图位于底栏后面)

下面的代码复制了automaticallyAdjustsScrollViewInsets

edgesForExtendedLayout = UIEdgeRectTop所做的事情
self.scrollView.contentInset = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, 0, 0);
self.scrollView.contentOffset = CGPointMake(0, -self.topLayoutGuide.length);

答案 1 :(得分:0)

我认为这取决于你的UIVIewController的edgesForExtendedLayout值。如果您希望内容显示在顶部之后,请设置edgesForExtendedLayout' = UIRectEdgeNone (or UIRectEdgeRight | UIRectEdgeLeft | UIRectEdgeBottom, you just don't want to include UIRectEdgeTop`)