當(dāng)我們在一個UIViewController中同時創(chuàng)建2個tableView的時候,如果把它們的frame中的Y坐標(biāo)設(shè)置為一樣,你可能會發(fā)現(xiàn)它們的位置并沒有達(dá)到你想要的結(jié)果.比如第一tableView個frame(0,0,320,568),另一個也frame(0,0,320,568),結(jié)果會發(fā)現(xiàn)第二個tableView的第一行數(shù)據(jù)被導(dǎo)航欄遮擋了,以至于我們不得已把第二個frame改成(0,64,320,568-64),雖然效果變成了我們想要的,但是卻不知道這是什么原因.......
附上截圖
其實(shí)這一切都是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.
由此可見,當(dāng)我們一個界面有多個tableView之類的,要將它設(shè)置為NO,完全由自己手動來布局,就不會錯亂了.