-
UIPickerView上隱藏兩根黑線的問題
-
tableview cell和footer、header的新屬性 backgroundConfiguration
-
UIPageControl 修改小點(diǎn)
-
keywindow的獲取問題
-
UIDatePicker 14 上顯示出問題(新增了屬性)
- 以前為了達(dá)到UI效果,隱藏pickerview上兩條黑線直接暴力訪問其子view數(shù)組,setHide;然 14開始subviews就兩個(gè)對(duì)象,直接報(bào)越界。。。
先粗暴的解決崩潰問題,如下????
// UIPickerView隱藏黑線
NSArray *subVArr = pickerView.subviews;
if (subVArr.count >= 2) {
[[subVArr objectAtIndex:1] setHidden:TRUE];
}
if (subVArr.count >= 3) {
[[subVArr objectAtIndex:2] setHidden:TRUE];
}
- 關(guān)于backgroundConfiguration直接說場(chǎng)景,應(yīng)用內(nèi)有個(gè)頁面用了tableView的sectionFooterView撐開一定高度達(dá)到設(shè)計(jì)效果,只return了其高度,而沒有實(shí)現(xiàn)viewForFooterInSection:。如此,在13及以下的系統(tǒng)測(cè)試都是沒問題的,14以上,發(fā)現(xiàn)會(huì)莫名其妙的多出一掉灰線,查看圖層發(fā)現(xiàn)是footerview上的一個(gè)默認(rèn)空間。由于沒有實(shí)現(xiàn)viewForFooterInSection,所以顯示的是系統(tǒng)提供的默認(rèn)樣式;如此說來需要設(shè)置這個(gè)東西為透明或隱藏,去到UITableViewHeaderFooterView頭文件發(fā)現(xiàn)多了個(gè)backgroundConfiguration屬性。好,找到問題了,那么動(dòng)手干掉他!
如下:
- (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的默認(rèn)圓點(diǎn)一般是不會(huì)和設(shè)計(jì)的樣式完全一樣的,那么、就需要我們開發(fā)仔自定義一下咯。。。
常見的有: layoutsubview時(shí)遍歷其子控件修改其顏色大小形狀等屬性,或者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"];
而我們項(xiàng)目里的pagecontrol的點(diǎn)需要7像素大小,就用了第一種修改frame的方式;14的時(shí)候問題來了,發(fā)現(xiàn)整個(gè)pagecontrol都看不到了。。。
此時(shí)點(diǎn)開圖層發(fā)現(xiàn)控件是在的,但是修改frame修改的無效;研究了一下發(fā)現(xiàn)是14后UIPageControl 的層級(jí)不一樣了,又被多套了幾層,有興趣的可以
// NSArray *subViews = self.subviews;
// if(@available(iOS 14.0, *)) {
// subViews = self.subviews.firstObject.subviews.firstObject.subviews.firstObject.subviews;
// }
這么試一下,你就會(huì)明白了。
但是我要解決問題啊!要能顯示出要求的大小,撓了會(huì)兒腦袋、、、沒啥好辦法,反正只是調(diào)整大小讓ta縮小點(diǎn)就是了??。就有了下邊這句:
[_pageControl setTransform:CGAffineTransformMakeScale(0.7, 0.7)];// 調(diào)小圓點(diǎn),默認(rèn)10,現(xiàn)需要7
我承認(rèn)我不是個(gè)合格的開發(fā)仔,我只要實(shí)現(xiàn)效果??。
- 說起 keywindow的獲取問題,其實(shí)不能算是14的鍋。。。畢竟13就改了,當(dāng)時(shí)沒在意,誰曾想前幾天通過一個(gè)地方暴露出了這個(gè)問題,場(chǎng)景為:某處需要顯示個(gè)alert在最頂層但是無法直接獲取當(dāng)前最頂層VC,就用了keywindow。rootVC去顯示,此時(shí)出事了。。。
@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ū)別對(duì)待獲取keywindow好了,有了如下代碼:
#if (__IPHONE_13_0)
#define KEYWINDOW [UIApplication sharedApplication].windows[0]
#elif (__IPHONE_9_0)
#define KEYWINDOW [[UIApplication sharedApplication] keyWindow]
#endif
- UIDatePicker 增加了pickerStyle,需要設(shè)置preferredDatePickerStyle = UIDatePickerStyleWheels才會(huì)和以前一樣,并且現(xiàn)在對(duì)frame的寬高設(shè)置已經(jīng)不生效了,會(huì)采用系統(tǒng)默認(rèn)的寬高。
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的時(shí)候設(shè)置了frame,14之后會(huì)
解決辦法:
- 設(shè)置frame放到datePickerMode后
- 或后續(xù)進(jìn)行約束
if (@available(iOS 14.0, *)) {
self.datePicker.preferredDatePickerStyle = UIDatePickerStyleCompact;
}
后續(xù)再發(fā)現(xiàn)問題,會(huì)及時(shí)補(bǔ)充,也歡迎評(píng)論區(qū)留下各位發(fā)現(xiàn)的一些問題??
原諒我才疏學(xué)淺,寫的亂七八糟 ??