iOS 11中tableView下移問題

1.如果不需要系統為你設置邊緣距離,可以做以下設置:

//如果iOS的系統是11.0,會有這樣一個宏定義“#define __IPHONE_11_0 110000”;如果系統版本低于11.0則沒有這個宏定義

ifdef __IPHONE_11_0

if ([tableView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
if (@available(iOS 11.0, )) {
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
_tableView.contentInset=UIEdgeInsetsMake(0, 0, 0, 0 );
/
屬性的解釋
/* When contentInsetAdjustmentBehavior allows, UIScrollView may incorporate
its safeAreaInsets into the adjustedContentInset.
@property(nonatomic, readonly) UIEdgeInsets adjustedContentInset API_AVAILABLE(ios(11.0),tvos(11.0));
*/
tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}

endif

contentInsetAdjustmentBehavior屬性也是用來取代automaticallyAdjustsScrollViewInsets屬性的,推薦使用這種方式。
2。實現代理

pragma mark 此方法加上是為了適配iOS 11出現的問題

  • (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
    }
  • (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
    }

//設置系統子的分割線對齊

  • (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
    [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
    [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    }
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 3月8日下午,我校二年四班學生家長滿懷感恩之心,把繡有“授業一絲不茍,解惑無微不至”的錦旗獻給了班主任于老...
    梁宇婷_ab7f閱讀 541評論 0 0
  • 關鍵對話“關鍵對話指的是每個人身上都會發生的和他人的互動行為,是指可影響你生活的那些日常對話......關鍵對話有...
    唐人生閱讀 220評論 0 1
  • 看著這張照片,仿佛時間被定格,情景重現,話音仿佛還在耳邊 剛去的時候就在拍賣,那三連畫就放在這個位...
    行云流水暢遨游閱讀 262評論 1 1