AutomaticallyAdjustsScrollViewInsets的坑

當我們在一個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,完全由自己手動來布局,就不會錯亂了.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 當我們在一個UIViewController中同時創建2個tableView的時候,如果把它們的frame中的Y坐...
    LeoAu閱讀 450評論 0 3
  • iOS 7 之后蘋果給 UIViewController 引入了 topLayoutGuide 和 bottomL...
    IOSCoderYummy閱讀 798評論 0 0
  • 有一個老人獨自住在一片荒蕪的山坡上。他會經常幫助過往的人們,給他們食物和水,或者給迷路的人們指路。平日里,他...
    諸無患閱讀 527評論 0 0
  • 花滿心時亦滿樓,這該是古龍筆下最驚艷的名字了。 愛花之人也熱愛著所有的生命。 對鮮花有著強烈的熱愛,如同他對所有生...
    嵐風的葉子閱讀 296評論 0 0
  • 數據分析過程: 1、以事實為基礎提出假設,界定問題 2、將問題細分,形成互不重疊的子問題 3、進行數據收集與分析,...
    田浩沛閱讀 862評論 0 4