-
UIPickerView上隱藏兩根黑線的問題
-
tableview cell和footer殴边、header的新屬性 backgroundConfiguration
-
UIPageControl 修改小點
-
keywindow的獲取問題
-
UIDatePicker 14 上顯示出問題(新增了屬性)
- 以前為了達到UI效果知态,隱藏pickerview上兩條黑線直接暴力訪問其子view數(shù)組,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];
}
- 關于backgroundConfiguration直接說場景缰雇,應用內(nèi)有個頁面用了tableView的sectionFooterView撐開一定高度達到設計效果入偷,只return了其高度,而沒有實現(xiàn)viewForFooterInSection:械哟。如此疏之,在13及以下的系統(tǒng)測試都是沒問題的,14以上戒良,發(fā)現(xiàn)會莫名其妙的多出一掉灰線体捏,查看圖層發(fā)現(xiàn)是footerview上的一個默認空間。由于沒有實現(xiàn)viewForFooterInSection糯崎,所以顯示的是系統(tǒng)提供的默認樣式几缭;如此說來需要設置這個東西為透明或隱藏,去到UITableViewHeaderFooterView頭文件發(fā)現(xiàn)多了個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;
}
- UIPageControl的默認圓點一般是不會和設計的樣式完全一樣的某抓,那么、就需要我們開發(fā)仔自定義一下咯惰瓜。否副。。
常見的有: 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的時候問題來了奈揍,發(fā)現(xiàn)整個pagecontrol都看不到了曲尸。。男翰。
此時點開圖層發(fā)現(xiàn)控件是在的另患,但是修改frame修改的無效;研究了一下發(fā)現(xiàn)是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涉馅,現(xiàn)需要7
我承認我不是個合格的開發(fā)仔归园,我只要實現(xiàn)效果??。
- 說起 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;
既然如此缕碎,那就區(qū)別對待獲取keywindow好了,有了如下代碼:
#if (__IPHONE_13_0)
#define KEYWINDOW [UIApplication sharedApplication].windows[0]
#elif (__IPHONE_9_0)
#define KEYWINDOW [[UIApplication sharedApplication] keyWindow]
#endif
- UIDatePicker 增加了pickerStyle池户,需要設置preferredDatePickerStyle = UIDatePickerStyleWheels才會和以前一樣咏雌,并且現(xiàn)在對frame的寬高設置已經(jīng)不生效了,會采用系統(tǒng)默認的寬高煞檩。
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后
- 或后續(xù)進行約束
if (@available(iOS 14.0, *)) {
self.datePicker.preferredDatePickerStyle = UIDatePickerStyleCompact;
}
后續(xù)再發(fā)現(xiàn)問題栅贴,會及時補充斟湃,也歡迎評論區(qū)留下各位發(fā)現(xiàn)的一些問題??
原諒我才疏學淺,寫的亂七八糟 ??