iPhoneX 適配問題

顯示黑條

1. 顯示黑條,即沒有沾滿屏幕,對于這個問題,添加一張 1125 * 2436的啟動圖即可.

啟動圖

2.關(guān)于 navi 在 iPhone X 上是88. 通過對 navi 圖層的觀察, navi 是從44開始的.其背景是向上偏移44,和之前狀態(tài)欄的思路是一樣的,只是偏移量不一樣.

navi 視圖

3.開發(fā)尺寸是375 * 812

ps: 如下面,由于要在 navi 上添加漸變的背景圖,要控制 navi 的高

- (UIImageView *)alphaView {
    if (!_alphaView) {
        CGRect frame = self.navigationBar.frame;
        CGFloat h = SCREEN_HEIGHT == 812 ? 88 : 64;
        UIImageView *alphaView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, h)];
        alphaView.image = [UIImage imageNamed:@"bg_gradient"];
        [self.navigationBar.subviews.firstObject insertSubview: alphaView atIndex:0];
        _alphaView = alphaView;
    }
    return _alphaView;
}

4. tabbar的高度為83

tabbar

5.當(dāng)使用 ScrollView 時,默認偏移量是88;

iOS11上automaticallyAdjustsScrollViewInsets = false這句代碼失效
在 iOS11中添加了新的屬性contentInsetAdjustmentBehavior,這個屬性是個枚舉值

typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) {
    UIScrollViewContentInsetAdjustmentAutomatic, // Similar to .scrollableAxes, but for backward compatibility will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewInsets = YES inside a navigation controller, regardless of whether the scroll view is scrollable
    UIScrollViewContentInsetAdjustmentScrollableAxes, // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)
    UIScrollViewContentInsetAdjustmentNever, // contentInset is not adjusted
    UIScrollViewContentInsetAdjustmentAlways, // contentInset is always adjusted by the scroll view's safeAreaInsets
} API_AVAILABLE(ios(11.0),tvos(11.0));

/*
automatic 和scrollableAxes一樣,scrollView會自動計算和適應(yīng)頂部和底部的內(nèi)邊距并且在scrollView 不可滾動時,也會設(shè)置內(nèi)邊距.
 scrollableAxes 自動計算內(nèi)邊距.
 never不計算內(nèi)邊距
always 根據(jù)safeAreaInsets 計算內(nèi)邊距
*/

所以我們要對 scrollview 進行如下設(shè)置,才能解決偏移88的問題.

if #available(iOS 11.0, *) {
  scrollerView.contentInsetAdjustmentBehavior = .never
}

未完,待更!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容