1. 程式人生 > >iOS UITableView顯示下移問題:automaticallyAdjustsScrollViewInsets 屬性淺談

iOS UITableView顯示下移問題:automaticallyAdjustsScrollViewInsets 屬性淺談

上週處理一個表格時,發現TableView實際顯示比設定的位置低了一段高度。查資料發現是iOS7之後,UIViewController增加了一個新屬性:automaticallyAdjustsScrollViewInsets;該屬性預設值為YES,將其設定為NO,表格顯示效果就正常了。

對於automaticallyAdjustsScrollViewInsets屬性,蘋果官方文件給出的註釋:

A Boolean value that indicates whether the view controller should automatically adjust its scroll view insets.


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 to NO if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.


簡而言之就是設定是否讓系統自動控制 scroll view 以讓其適配螢幕區域中的狀態列、導航欄、tab欄等。

網上很多開發者批評這個屬性毫無用處、坑爹,不過我感覺這個屬性還是有點用處的,因為讓讓系統自己適配scroll view 時,可以實現scroll view 滾動時是覆蓋全屏的,這樣相較於我們自己設定frame時滾動僅在可見範圍內,視覺效果感受上會有所提升。