1.滾動條高度跳動板壮、上下拉刷新問題:
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
2. 列表/頁面偏移
本來是這樣的
if (@available(iOS 11.0, *)){
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
目前發(fā)現(xiàn)所有的Scrollview 及其子類都需要設(shè)置 contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever 辩昆,工程中大量使用列表的同學(xué)不要慌,不要忙西设,因為UIView及其子類都遵循UIAppearance協(xié)議,我們可以進(jìn)行全局配置:
// AppDelegate 進(jìn)行全局設(shè)置
if (@available(iOS 11.0, *)){
[[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
}
這樣一來使用UITableview 答朋、UICollectionView贷揽、UIScrollview的時候就不需要再單獨設(shè)置該屬性了。
3. 導(dǎo)航欄按鈕位置問題
之前這樣寫控制按鈕的邊距
//調(diào)整按鈕邊距
UIBarButtonItem* spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
//將寬度設(shè)為負(fù)值
spaceItem.width= -5;
[items addObject:spaceItem];
今日不同往日梦碗,此方法無效了禽绪。
我試著使用了下面的方法
pragma mark ————— 導(dǎo)航欄 添加文字按鈕 —————
- (NSMutableArray<UIButton *> *)addNavigationItemWithTitles:(NSArray *)titles isLeft:(BOOL)isLeft target:(id)target action:(SEL)action tags:(NSArray *)tags
{
NSMutableArray * items = [[NSMutableArray alloc] init];
//調(diào)整按鈕位置
// UIBarButtonItem* spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
//將寬度設(shè)為負(fù)值
// spaceItem.width= -5;
// [items addObject:spaceItem];
NSMutableArray * buttonArray = [NSMutableArray array];
NSInteger i = 0;
for (NSString * title in titles) {
UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 30, 30);
[btn setTitle:title forState:UIControlStateNormal];
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
btn.titleLabel.font = SYSTEMFONT(16);
[btn setTitleColor:KWhiteColor forState:UIControlStateNormal];
btn.tag = [tags[i++] integerValue];
[btn sizeToFit];
//設(shè)置偏移
if (isLeft) {
[btn setContentEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
}else{
[btn setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, -10)];
}
UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:btn];
[items addObject:item];
[buttonArray addObject:btn];
}
if (isLeft) {
self.navigationItem.leftBarButtonItems = items;
} else {
self.navigationItem.rightBarButtonItems = items;
}
return buttonArray;
}
圖層調(diào)試發(fā)現(xiàn)此法其實屬障眼法,并不完美洪规,設(shè)置內(nèi)容偏移印屁,其實際位置并沒有發(fā)生變化,這可能導(dǎo)致按鈕部分區(qū)域無法點擊淹冰,目前偏移10像素問題不大库车,其他請自行測試,若有更完美的辦法請聯(lián)系我更新樱拴。
4. 位置權(quán)限
在IOS11柠衍,原有的NSLocationAlwaysUsageDeion被降級為NSLocationWhenInUseUsageDeion。因此晶乔,在原來項目中使用requestAlwaysAuthorization獲取定位權(quán)限珍坊,而未在plist文件中配置NSLocationAlwaysAndWhenInUseUsageDeion,系統(tǒng)框不會彈出正罢。建議新舊key值都在plist里配置阵漏,反正我試下來是沒有問題,唯一的區(qū)別是使用requestAlwaysAuthorization獲取權(quán)限 IOS11系統(tǒng)彈框會把幾種權(quán)限級別全部列出翻具,供用戶選擇履怯,顯然更人性化了。
快去更新你的info.plist
<!-- 位置 -->
<key>NSLocationUsageDescription</key>
<string>獲取地理位置裆泳,精準(zhǔn)推送服務(wù)</string>
<!-- 在使用期間訪問位置 -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>獲取地理位置叹洲,精準(zhǔn)推送服務(wù)</string>
<!-- 始終訪問位置 -->
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始終訪問位置</string>
<!-- iOS 11訪問位置 -->
<key>NSLocationAlwaysAndWhenInUseUsageDeion</key>
<string>App需要您的同意,才能始終訪問位置</string>