1. 程式人生 > >iOS11遇到的坑及解決方法

iOS11遇到的坑及解決方法

1、iOS 11之前的導航欄的高度是64px(狀態條+導航欄),iOS11之後如果設定了prefersLargeTitles = YES(預設NO)則為96pt。所以一般不用管。

2、在iOS 11上執行tableView向下偏移64px或者20px,因為iOS 11廢棄了automaticallyAdjustsScrollViewInsets,而是給UIScrollView增加了contentInsetAdjustmentBehavior屬性。避免這個坑的方法是要判斷

1 2 3 4 5 if (@available(iOS 11.0, *)) { _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}else { self.automaticallyAdjustsScrollViewInsets = NO; }

3、tableView的sectionHeader、sectionFooter高度與設定不符,因為tableView的estimatedRowHeight、estimatedSectionHeaderHeight、 estimatedSectionFooterHeight三個高度估算屬性由預設的0變成了UITableViewAutomaticDimension。最簡單的方法就是直接設定為0。

4、iPhone X狀態條由20px變成了44px,UITabBar由49px變成了83px。設定佈局時y直接寫成64的就要根據機型設定。可以設定巨集

#define Device_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO),

然後再設定。