關于升級iOS 14后我的項目中引起的一些bug(15之前會持續更新)

  • UIPickerView上隱藏兩根黑線的問題

  • tableview cell和footer、header的新屬性 backgroundConfiguration

  • UIPageControl 修改小點

  • keywindow的獲取問題

  • UIDatePicker 14 上顯示出問題(新增了屬性)


  1. 以前為了達到UI效果,隱藏pickerview上兩條黑線直接暴力訪問其子view數組,setHide;然 14開始subviews就兩個對象,直接報越界。。。
    先粗暴的解決崩潰問題,如下????
// UIPickerView隱藏黑線
    NSArray *subVArr = pickerView.subviews;
    if (subVArr.count >= 2) {
        [[subVArr objectAtIndex:1] setHidden:TRUE];
    }
    if (subVArr.count >= 3) {
        [[subVArr objectAtIndex:2] setHidden:TRUE];
    }

  1. 關于backgroundConfiguration直接說場景,應用內有個頁面用了tableView的sectionFooterView撐開一定高度達到設計效果,只return了其高度,而沒有實現viewForFooterInSection:。如此,在13及以下的系統測試都是沒問題的,14以上,發現會莫名其妙的多出一掉灰線,查看圖層發現是footerview上的一個默認空間。由于沒有實現viewForFooterInSection,所以顯示的是系統提供的默認樣式;如此說來需要設置這個東西為透明或隱藏,去到UITableViewHeaderFooterView頭文件發現多了個backgroundConfiguration屬性。好,找到問題了,那么動手干掉他!

如下:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UITableViewHeaderFooterView *fv = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"xxxxxxlSectionFooterView"];
    if (!fv) {
        fv = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"xxxxxxCellSectionFooterView"];
        if (@available(iOS 14.0, *)) {
            fv.backgroundConfiguration = [UIBackgroundConfiguration clearConfiguration];
        } else {
            // Fallback on earlier versions
        }
    }

    return fv;
}


  1. UIPageControl的默認圓點一般是不會和設計的樣式完全一樣的,那么、就需要我們開發仔自定義一下咯。。。
    常見的有: layoutsubview時遍歷其子控件修改其顏色大小形狀等屬性,或者setKeyValue(早已被?粑粑抵制??)
 for (int i = 0; i < [subViews count]; i ++) {
//        UIImageView *dot = [subViews objectAtIndex:i];
//
//        if (i == self.currentPage) {
//            [dot setFrame:CGRectMake(i * marginX, dot.frame.origin.y, 7, 7)];
//        }else {
//            [dot setFrame:CGRectMake(i * marginX, dot.frame.origin.y, 7, 7)];
//        }
//    }
//        [_pageContrl setValue:[UIImage imageNamed:@"pagecontrol_dot_current"] forKeyPath:@"_currentPageImage"];
//        [_pageContrl setValue:[UIImage imageNamed:@"pagecontrol_dot"] forKeyPath:@"_pageImage"];

而我們項目里的pagecontrol的點需要7像素大小,就用了第一種修改frame的方式;14的時候問題來了,發現整個pagecontrol都看不到了。。。
此時點開圖層發現控件是在的,但是修改frame修改的無效;研究了一下發現是14后UIPageControl 的層級不一樣了,又被多套了幾層,有興趣的可以

//    NSArray *subViews = self.subviews;
//    if(@available(iOS 14.0, *)) {
//        subViews = self.subviews.firstObject.subviews.firstObject.subviews.firstObject.subviews;
//    }

這么試一下,你就會明白了。
但是我要解決問題??!要能顯示出要求的大小,撓了會兒腦袋、、、沒啥好辦法,反正只是調整大小讓ta縮小點就是了??。就有了下邊這句:

        [_pageControl setTransform:CGAffineTransformMakeScale(0.7, 0.7)];// 調小圓點,默認10,現需要7

我承認我不是個合格的開發仔,我只要實現效果??。


  1. 說起 keywindow的獲取問題,其實不能算是14的鍋。。。畢竟13就改了,當時沒在意,誰曾想前幾天通過一個地方暴露出了這個問題,場景為:某處需要顯示個alert在最頂層但是無法直接獲取當前最頂層VC,就用了keywindow。rootVC去顯示,此時出事了。。。

@property(nullable, nonatomic,readonly) UIWindow *keyWindow API_DEPRECATED("Should not be used for applications that support multiple scenes as it returns a key window across all connected scenes", ios(2.0, 13.0));
@property(nonatomic,readonly) NSArray<__kindof UIWindow *> *windows;

既然如此,那就區別對待獲取keywindow好了,有了如下代碼:

#if (__IPHONE_13_0)
#define KEYWINDOW [UIApplication sharedApplication].windows[0]
#elif (__IPHONE_9_0)
#define KEYWINDOW [[UIApplication sharedApplication] keyWindow]
#endif

  1. UIDatePicker 增加了pickerStyle,需要設置preferredDatePickerStyle = UIDatePickerStyleWheels才會和以前一樣,并且現在對frame的寬高設置已經不生效了,會采用系統默認的寬高。
    preferredDatePickerStyle屬性:
typedef NS_ENUM(NSInteger, UIDatePickerStyle) {
    /// Automatically pick the best style available for the current platform & mode.
    UIDatePickerStyleAutomatic,
    /// Use the wheels (UIPickerView) style. Editing occurs inline.
    UIDatePickerStyleWheels,
    /// Use a compact style for the date picker. Editing occurs in an overlay.
    UIDatePickerStyleCompact,
    /// Use a style for the date picker that allows editing in place.
    UIDatePickerStyleInline API_AVAILABLE(ios(14.0)) API_UNAVAILABLE(tvos, watchos),
} API_AVAILABLE(ios(13.4)) API_UNAVAILABLE(tvos, watchos);
  • 貌似我以前封裝的顯示DatePicker的控件里是在init的時候設置了frame,14之后會

解決辦法:

  • 設置frame放到datePickerMode后
  • 或后續進行約束
     if (@available(iOS 14.0, *)) {
        self.datePicker.preferredDatePickerStyle = UIDatePickerStyleCompact;
     } 


后續再發現問題,會及時補充,也歡迎評論區留下各位發現的一些問題??



原諒我才疏學淺,寫的亂七八糟 ??

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

推薦閱讀更多精彩內容