當我們在一個UIViewController中同時創建2個tableView的時候,如果把它們的frame中的Y坐標設置為一樣,你可能會發現它們的位置并沒有達到你想要的結果.比如第一tableView個frame(0,0,320,568),另一個也frame(0,0,320,568),結果會發現第二個tableView的第一行數據被導航欄遮擋了,以至于我們不得已把第二個frame改成(0,64,320,568-64),雖然效果變成了我們想要的,但是卻不知道這是什么原因.......
其實這一切都是automaticallyAdjustsScrollViewInsets在作怪,我們可以先看一下官方文檔中對它的描述:
automaticallyAdjustsScrollViewInsets
Specifies whether or not the view controller should automatically adjust its scroll view insets.
@property(nonatomic, assign) BOOL automaticallyAdjustsScrollViewInsets
Discussion
Default value is YES, 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 toNO if 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
當我們一個界面有多個tableView之類的, 將它設置為NO,完全由自己手動來布局,就不會錯亂了.