http://www.cocoachina.com/ios/20170917/20590.html
適配iOS11 - UITableview UICollectionView MJRefresh下拉刷新錯(cuò)亂
http://www.itdecent.cn/p/94d3fdc0f20d
適配中的問題及解決辦法
1. 滾動(dòng)條高度跳動(dòng)、上下拉刷新問題:
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é)不要慌,不要忙,因?yàn)閁IView及其子類都遵循UIAppearance協(xié)議,我們可以進(jìn)行全局配置:
// AppDelegate 進(jìn)行全局設(shè)置
if (@available(iOS 11.0, *)){
[[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
}
這樣一來使用UITableview 、UICollectionView、UIScrollview的時(shí)候就不需要再單獨(dú)設(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 *)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í)屬障眼法,并不完美,設(shè)置內(nèi)容偏移,其實(shí)際位置并沒有發(fā)生變化,這可能導(dǎo)致按鈕部分區(qū)域無法點(diǎn)擊,目前偏移10像素問題不大,其他請(qǐng)自行測(cè)試,若有更完美的辦法請(qǐng)聯(lián)系我更新。
4. 位置權(quán)限
在IOS11,原有的NSLocationAlwaysUsageDeion被降級(jí)為NSLocationWhenInUseUsageDeion。因此,在原來項(xiàng)目中使用requestAlwaysAuthorization獲取定位權(quán)限,而未在plist文件中配置NSLocationAlwaysAndWhenInUseUsageDeion,系統(tǒng)框不會(huì)彈出。建議新舊key值都在plist里配置,反正我試下來是沒有問題,唯一的區(qū)別是使用requestAlwaysAuthorization獲取權(quán)限 IOS11系統(tǒng)彈框會(huì)把幾種權(quán)限級(jí)別全部列出,供用戶選擇,顯然更人性化了。
快去更新你的info.plist
NSLocationUsageDescription
獲取地理位置,精準(zhǔn)推送服務(wù)
NSLocationWhenInUseUsageDescription
獲取地理位置,精準(zhǔn)推送服務(wù)
NSLocationAlwaysUsageDescription
App需要您的同意,才能始終訪問位置
NSLocationAlwaysAndWhenInUseUsageDeion
App需要您的同意,才能始終訪問位置
5. iPhone X 適配
iPhone X 變化最大的是頭部 & 底部
非iPhone X :
StatusBar高20px,NavigationBar高44px,底部TabBar高49px
iPhone X:
StatusBar高44px,NavigationBar高44px,底部TabBar高83px
所以,之前項(xiàng)目里寫死的 ±49 ±64 都要出問題,如果你之前抽離出來使用的是宏,那問題不大,如果不是,開始搬磚吧少年。
送你幾個(gè)宏,來日好好擼,莫偷懶
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define kNavBarHeight 44.0
//注意:請(qǐng)直接獲取系統(tǒng)的tabbar高度,若沒有用系統(tǒng)tabbar,建議判斷屏幕高度;之前判斷狀態(tài)欄高度的方法不妥,如果正在通話狀態(tài)欄會(huì)變高,導(dǎo)致判斷異常,下面只是一個(gè)例子,請(qǐng)勿直接使用!
#define kTabBarHeight kAppDelegate.mainTabBar.tabBar.frame.size.height
#define kTopHeight (kStatusBarHeight + kNavBarHeight)
替換 64px →kTopHeight
替換 49px →kTabBarHeight
6. iPhone X push的時(shí)候TabBar上移
答案在這:適配iPhone X Push過程中TabBar位置上移
這樣可以解決大部分因位置導(dǎo)致的適配問題
作者:臭碼農(nóng)
鏈接:http://www.itdecent.cn/p/94d3fdc0f20d
來源:簡書
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處。