1. 程式人生 > >[iOS11] contentInsetAdjustmentBehavior 問題, push back時, 界面會上下移動.

[iOS11] contentInsetAdjustmentBehavior 問題, push back時, 界面會上下移動.

text iap nav 需要 tac del http XML gate

https://stackoverflow.com/questions/45573829/weird-uitableview-behaviour-in-ios11-cells-scroll-up-with-navigation-push-anima

在你的tablview/controller基類設置

 if (@available(ios 11.0,*)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }

不要用 `[UIScrollView appearance]

` 的方法, 不生效.

PS: 搜索這個問題的話, 國內的多個文章都是抄的同一篇, 且是錯的.

如下是錯的.

  1. 目前發現所有的Scrollview 及其子類都需要設置 contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever ,
  2. 工程中大量使用列表的同學不要慌,不要忙,因為UIView及其子類都遵循UIAppearance協議,我們可以進行全局配置:
  3. // AppDelegate 進行全局設置
  4. if (@available(iOS 11.0, *)){
  5. [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
  6. }
  7. 這樣一來使用UITableview 、UICollectionView、UIScrollview的時候就不需要再單獨設置該屬性了。

[iOS11] contentInsetAdjustmentBehavior 問題, push back時, 界面會上下移動.