iOS適配相關

問題一

  • 描述
    • 當列表有多余一頁的數(shù)據(jù),上拉加載數(shù)據(jù)且reloadData完成后,tableView的contentOffset發(fā)生了不必要的變化,導致列表會向上拉動一段位移,觀察發(fā)現(xiàn),reloadData之后,tableViewcontentOffset發(fā)生了幾次變化。
    • 如圖


      image.png
  • 原因
    Google了一下,發(fā)現(xiàn)原因是 iOS11 中默認開啟了Self-Sizing,即Headers, Footers, and Cells都默認開啟Self-Sizing,所有estimated高度默認值從iOS11之前的0.0改變?yōu)?code>UITableViewAutomaticDimension。我們的項目雖然沒有使用estimateRowHeight屬性,在iOS11的環(huán)境下默認開啟Self-Sizing之后,這樣就會造成contentSizecontentOffset值發(fā)生不可預知的變化,如果是有動畫是觀察這兩個屬性的變化進行的,就會造成動畫的異常,因為在估算行高機制下,contentSize的值是一點點地變化更新的,所有cell顯示完后才是最終的contentSize值,因為不會緩存正確的行高,reloadData的時候,會重新計算contentSize,就有可能會引起contentOffset的變化
@property (nonatomic) CGFloat estimatedRowHeight NS_AVAILABLE_IOS(7_0); // default is UITableViewAutomaticDimension, set to 0 to disable
  • 解決方案
    通過關閉Self-Sizing,可以解決上述問題
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;

問題二

  • 描述
    • 報名榜樣房UI錯亂
    • 如圖


      image.png
  • 原因
    iOS11對導航欄有較大改動,現(xiàn)在rightBarButtonItem是不能獲取到相對于導航欄的坐標了
_lineImageView.left = frame.origin.x + frame.size.width / 2.0;
  • 解決方案
    因沒有找到合適獲取坐標的方案,所以給定了左邊距離邊框的寬度
_lineImageView.left = yScreenWidth - (18.0 + frame.size.width / 2.0);

問題三

  • 描述
    • 各種主頁下拉箭頭露了出來
    • 如圖


      image.png
    • 解決方案
if (kSystemVersion >= 11.0 && [self.managerOwner isKindOfClass:[UIScrollView class]]) {
            UIScrollView *tempScrollView = (UIScrollView *)self.managerOwner;
            if (@available(iOS 11.0, *)) {
                tempScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            }
        }

問題四

  • 描述
    • TabBar發(fā)布按鈕點擊,奔潰!
    • 日志如下
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<UIView: 0x127dcd820; frame = (0 0; 320 568); layer = <CALayer: 0x1c0239600>> has been added as a subview to <UIVisualEffectView: 0x127dcbda0; frame = (0 0; 320 568); layer = <CALayer: 0x1c022fd00>>. Do not add subviews directly to the visual effect view itself, instead add them to the -contentView.'
  • 原因
    查看UIVisualEffectView發(fā)現(xiàn)了不能在它上面直接添加子視圖,需要添加在它的contentView上
@property (nonatomic, strong, readonly) UIView *contentView; // Do not add subviews directly to UIVisualEffectView, use this view instead.
  • 解決方案
//[self.bgView addSubview:self.contentView];
[self.bgView.contentView addSubview:self.contentView];

上面的bgView是UIVisualEffectView

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容