亚洲成Av人片在线观看不卡|中文字幕在线精品无码一区|国产精品福利午夜h视频|手机看片AV永久免费,91天堂在线视频,最新2021年偷拍精品视频,国产成人一区二区在线视频

您當前的位置 :寧夏資訊網(wǎng) > 消費 >  內(nèi)容正文
投稿

博客 - CocoaChina

寧夏資訊網(wǎng) 2020-04-29 08:13:56 來源: 閱讀:-

一.bug展示

Xcode 升級到 版本后,公司中的項目運行到iOS11的設備上出現(xiàn)了一個UI Bug,原來自動適配tableview的內(nèi)間距失效了. 很顯然,tableView有了額外的內(nèi)邊距.代碼運行到之前的環(huán)境上是沒問題的,可用Xcode9一編譯,再跑到iOS11上就會出現(xiàn)問題...

二.問題產(chǎn)生原因

先貼一段設置tableView的代碼

private func setupTableView() { tableView = UITableView() tableView.frame = view.bounds tableView.dataSource = self tableView.delegate = self tableView.backgroundColor = UIColor.red extendedLayoutIncludesOpaqueBars = true; automaticallyAdjustsScrollViewInsets = false; // 設置tableView的內(nèi)邊距(能夠顯示出導航欄和tabBar下覆蓋的內(nèi)容) tableView.contentInset = UIEdgeInsetsMake(64, 0, 49, 0) // 設置內(nèi)容指示器(滾動條)的內(nèi)邊距 tableView.scrollIndicatorInsets = tableView.contentInset } 關于extendedLayoutIncludesOpaqueBars和automaticallyAdjustsScrollViewInsets

這兩個屬性屬于UIViewController 默認情況下extendedLayoutIncludesOpaqueBars = false 擴展布局不包含導航欄 默認情況下automaticallyAdjustsScrollViewInsets = true 自動計算滾動視圖的內(nèi)容邊距 但是,當 導航欄 是 不透明時,而tabBar為透明的時候,為了正確顯示tableView的全部內(nèi)容,需要重新設置這兩個屬性的值,然后設置contentInset(參考代碼). 上面的代碼邏輯沒有問題,但是放到iOS11 上為啥錯了呢? 找了半天,點開了automaticallyAdjustsScrollViewInsets 這個屬性,發(fā)現(xiàn)這個屬性在iOS11過期了,如圖:

在OC的聲明中,這個屬性是這樣的: @property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets API_DEPRECATED_WITH_REPLACEMENT("Use UIScrollView's contentInsetAdjustmentBehavior instead", ios(),tvos()); // Defaults to YES 這說明在iOS11 中, UIViewController的automaticallyAdjustsScrollViewInsets屬性已經(jīng)不再使用,我們需要使用UIScrollView的 contentInsetAdjustmentBehavior 屬性來替代它.

關于contentInsetAdjustmentBehavior

@available(iOS 11.0, *) public enum UIScrollViewContentInsetAdjustmentBehavior : Int {

case automatic // Similar to .scrollableAxes, but will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewContentInset = YES inside a navigation controller, regardless of whether the scroll view is scrollable

case scrollableAxes // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)

case never // contentInset is not adjusted

case always // contentInset is always adjusted by the scroll view's safeAreaInsets

} UIScrollViewContentInsetAdjustmentBehavior 是一個枚舉類型,值有以下幾種:

automatic 和scrollableAxes一樣,scrollView會自動計算和適應頂部和底部的內(nèi)邊距并且在scrollView 不可滾動時,也會設置內(nèi)邊距. scrollableAxes 自動計算內(nèi)邊距. never不計算內(nèi)邊距 always 根據(jù)safeAreaInsets 計算內(nèi)邊距 很顯然,我們這里要設置為 never 三.開始適配

swift 中

private func setupTableView() { tableView = UITableView() tableView.frame = view.bounds tableView.dataSource = self tableView.delegate = self tableView.backgroundColor = UIColor.red

    extendedLayoutIncludesOpaqueBars = true;
    if #available(iOS 11.0, *) {
        tableView.contentInsetAdjustmentBehavior = .never
    } else {
        automaticallyAdjustsScrollViewInsets = false;
    };
    tableView.contentInset = UIEdgeInsetsMake(64, 0, 49, 0)
    tableView.scrollIndicatorInsets = tableView.contentInset

} OC 中

self.extendedLayoutIncludesOpaqueBars = YES; if (@available(iOS 11.0, *)) { self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { self.automaticallyAdjustsScrollViewInsets = NO; } _tableView.contentInset = UIEdgeInsetsMake(64, 0, 49, 0); _tableView.scrollIndicatorInsets = _tableView.contentInset;

(正文已結(jié)束)

推薦閱讀:西安信息網(wǎng)

免責聲明及提醒:此文內(nèi)容為本網(wǎng)所轉(zhuǎn)載企業(yè)宣傳資訊,該相關信息僅為宣傳及傳遞更多信息之目的,不代表本網(wǎng)站觀點,文章真實性請瀏覽者慎重核實!任何投資加盟均有風險,提醒廣大民眾投資需謹慎!

網(wǎng)站簡介 - 聯(lián)系我們 - 營銷服務 - 老版地圖 - 版權(quán)聲明 - 網(wǎng)站地圖
Copyright.2002-2019 寧夏資訊網(wǎng) 版權(quán)所有 本網(wǎng)拒絕一切非法行為 歡迎監(jiān)督舉報 如有錯誤信息 歡迎糾正
青海省| 金坛市| 穆棱市| 米易县| 鲜城| 伽师县| 互助| 嘉祥县| 清苑县| 闽清县| 祁阳县| 冷水江市| 称多县| 玉环县| 镇安县| 门头沟区| 荥阳市| 渭南市| 大足县| 龙门县| 余庆县| 贵阳市| 巢湖市| 穆棱市| 芜湖县| 丹巴县| 拜城县| 塘沽区| 高邮市| 绥宁县| 乾安县| 广德县| 海盐县| 涿鹿县| 垣曲县| 三穗县| 昌平区| 克山县| 如皋市| 稻城县| 老河口市|