當(dāng)我們在一個(gè)UIViewController中同時(shí)創(chuàng)建2個(gè)tableView的時(shí)候,如果把它們的frame中的Y坐標(biāo)設(shè)置為一樣,你可能會(huì)發(fā)現(xiàn)它們的位置并沒有達(dá)到你想要的結(jié)果.比如第一tableView個(gè)frame(0,0,320,568),另一個(gè)也frame(0,0,320,568),結(jié)果會(huì)發(fā)現(xiàn)第二個(gè)tableView的第一行數(shù)據(jù)被導(dǎo)航欄遮擋了,以至于我們不得已把第二個(gè)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.
Declared In
UIViewController.h
當(dāng)我們一個(gè)界面有多個(gè)tableView之類的, 將它設(shè)置為NO,完全由自己手動(dòng)來布局,就不會(huì)錯(cuò)亂了.