最近項(xiàng)目升級(jí)到iOS 11,遇到一些問題,在此記錄一下!
一. push 新界面,出現(xiàn)一個(gè)從左往右并且從下往上移動(dòng)的問題
解決辦法:
設(shè)置UIScrollView的 contentInsetAdjustmentBehavior的屬性值為UIScrollViewContentInsetAdjustmentNever就可以。
二. 圖片保存到相冊崩潰問題
iOS11 圖片保存到相冊需要在在plist里面權(quán)限說明添加:
<key>NSPhotoLibraryAddUsageDescription</key>
<string>相冊添加圖片權(quán)限</string>
三. tableView 向下偏移20問題適配
// tableView 偏移20/64適配
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也適用
}else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
四. tableView 如果是Gruop類型的話,section之間的間距變寬,執(zhí)行返回高度的同時(shí)還需要執(zhí)行return UIView的代理,才起作用。
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc] init];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] init];
}
五.tableView 刷新 或者 滾動(dòng) 出現(xiàn)異常問題。
解決方法:
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
因?yàn)樵?code>iOS 11中默認(rèn)啟用Self-Sizing,Headers, footers, and cells都默認(rèn)開啟Self-Sizing, 所有estimated高度默認(rèn)值從iOS 11之前的0改變?yōu)?code>UITableViewAutomaticDimension。
@property (nonatomic) CGFloat estimatedRowHeight NS_AVAILABLE_IOS(7_0); // default is UITableViewAutomaticDimension, set to 0 to disable
如果目前項(xiàng)目中沒有啟用estimateRowHeight屬性,在iOS11的環(huán)境下就要注意,因?yàn)殚_啟Self-Sizing之后,tableView是使用estimateRowHeight屬性的,這樣就會(huì)造成contentSize 和 contentOffset值變化,如果是有動(dòng)畫觀察這兩個(gè)屬性的變化進(jìn)行的,就會(huì)造成動(dòng)畫異常,因?yàn)樵诠浪阈懈邫C(jī)制下,contentSize的值是一點(diǎn)點(diǎn)地變化更新的,所有cell顯示完成后才得到最終的contentSize值。因?yàn)椴粫?huì)緩存正確的行高,[tableView raloadData]的時(shí)候,會(huì)重新計(jì)算contentSize, 就有可能引起contentOffset的變化。iOS11不想使用Self-Sizing的話,可以通過以下方式關(guān)閉:
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
六.__NSArrayI類型和__NSArrayM類型直接通過索引獲取內(nèi)容,底部調(diào)用函數(shù)更改為:
- (ObjectType)objectAtIndexedSubscript:(NSUInteger)idx API_AVAILABLE(macos(10.8), ios(6.0), watchos(2.0), tvos(9.0));
所以如果通過攔截器,攔截防止數(shù)組越界,應(yīng)對(duì)這個(gè)函數(shù)進(jìn)行攔截。具體可以看:FJAvoidCrashMechanism。
七.自定義導(dǎo)航欄 偏移問題
在Xcode 9.0,iOS 11下,自定義導(dǎo)航欄呈如下狀態(tài):

具體原因可以查看這篇文章: App界面適配iOS11(包括iPhoneX的奇葩尺寸
解決辦法:
在自定義導(dǎo)航欄內(nèi)部進(jìn)行判斷:
#import "DJMsgListNavigationBar.h"
@implementation DJMsgListNavigationBar
#pragma mark --- layout method
-(void)layoutSubviews{
[super layoutSubviews];
CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
if (rectStatus.size.height==44.f) {
}else{
if (@available(iOS 11.0, *)) {
for ( UIView*aView in self.subviews) {
if ([NSStringFromClass(aView.classForCoder) isEqualToString:@"_UINavigationBarContentView"]) {
aView.frame = CGRectMake( 0,20,aView.frame.size.width,44);
}
else if ([NSStringFromClass(aView.classForCoder) isEqualToString:@"_UIBarBackground"]) {
aView.frame = CGRectMake(0,0,aView.frame.size.width, 64);
}
}
}
}
}