如果使用了 automaticallyAdjustsScrollViewInsets 這個屬性,那就不關 MJRefresh 的事了,很不幸,iOS11棄用了 automaticallyAdjustsScrollViewInsets 屬性,而是新增了 contentInsetAdjustmentBehavior 來替代它,這是 UIScrollView 的一個屬性,若在iOS11中使用 UIScrollView 及其子類并不想系統幫我們自動設置邊距,就要這樣設置:
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
if (@available(iOS 11.0, *)) {
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
if ([scrollView isKindOfClass:[UITableView class]]) {
// iOS 11的tableView自動算高默認自動開啟,不想使用則要這樣關閉
UITableView *tableView = (UITableView *)scrollView;
tableView.estimatedRowHeight = 0;
tableView.estimatedSectionHeaderHeight = 0;
tableView.estimatedSectionFooterHeight = 0;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
另外如果也不想使用iOS 11的導航欄 titleView 的變大變小效果,使用自定義的 titleView 尺寸,就要在自定義的 titileView 內部,重寫 intrinsicContentSize 方法,返回想要尺寸。
- (CGSize)intrinsicContentSize {
return self.contentSize;
}