- iOS 11 適配
1.1. tableview適配
// tableView 偏移20/64適配
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也適用
}else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
//滾動條高度跳動善涨、上下拉刷新問題:
self.estimatedRowHeight = 0;//默認是這樣設(shè)置,能防止上下拉刷新跳動問題栗恩,但是如果是xib自動cell漾抬,要把這行注釋注竿,然后給高度花颗。
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
// AppDelegate 進行全局設(shè)置
if (@available(iOS 11.0, *)){
[[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
}
//Warn:webView,scrollview,tableview都有頁面偏移問題,所以都要設(shè)置.
1.2 HUD不顯示
HUD 必須添加在窗口的keyWindow才能顯示,ios11在lastWindow在 是無法顯示的.
1.3 搜索欄適配
在ios11搜索欄 展示效果非常不好,只能重新適配.所以只能拋棄系統(tǒng)的UISearchBar,自己實現(xiàn)了一個搜索控件,由UIView實現(xiàn),主要是要實現(xiàn)
-(CGSize)intrinsicContentSize{
return UILayoutFittingExpandedSize;
}
在ios11 下搜索框能在titieView下自動擴張.
1.4 ios11導(dǎo)航欄按鈕圖片變大
UIButton *leftCustomButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
[leftCustomButton.widthAnchor constraintEqualToConstant:35].active = YES;
[leftCustomButton.heightAnchor constraintEqualToConstant:35].active = YES;
[leftCustomButton setImage:[UIImage imageNamed:@"defaultImage"] forState:UIControlStateNormal];
UIBarButtonItem * leftButtonItem =[[UIBarButtonItem alloc] initWithCustomView:leftCustomButton];
self.navigationItem.leftBarButtonItems = @[self.headerIconItem];
2.iPhoneX適配
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define kNavBarHeight 44.0
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)
#define kTopHeight (kStatusBarHeight + kNavBarHeight)
kStatusBarHeight與kTabBarHeight需要更改,還有不要隱藏statusBar.
3.tableview數(shù)組越界
判斷數(shù)組為空時候的越界問題當首次數(shù)據(jù)沒有請求完畢的時候[tableVIew reloadData];就會導(dǎo)致crash這個時候需要做一次判斷:
if(self.dataArray.count != 0){
Model * model = self.dataArray[indexPath.row];
}
有時候會出現(xiàn)上拉加載更多后點擊下拉出現(xiàn)crash 這個時候提示數(shù)組越界但是并不是真的越界 因為這個時候的indexpath.row > 數(shù)組的元素個數(shù)的大刊。所以需要以下處理
if(indexPath.row < self.dataArray.count){
Model* model = slef.dataArray[indexpath.row];
}
//即:
if(self.dataArray.count != 0 && indexPath.row < self.dataArray.count){
Model * model = self.dataArray[indexPath.row];
}
//FIXME:這方案不知道對不對,后續(xù)改正
4.修改UIAlertView設(shè)置文字左對齊
因為iphoneSDK默認是居中對齊的淀弹,而且沒有提供方法設(shè)置文本對齊接口夫壁,在Delegate中:
- (void)willPresentAlertView:(UIAlertView *)alertView;
獲取UIAlertView上面的Message控件拾枣,它其實也是一個UILable控件,然后設(shè)置其textAlignment的屬性即可盒让。
代碼如下:
- (void)willPresentAlertView:(UIAlertView *)alertView{
UIView * view = [alertView.subviews objectAtIndex:2];
if([view isKindOfClass:[UILabel class]]){
UILabel* label = (UILabel*) view;
label.textAlignment = UITextAlignmentLeft;
}
}
這里要注意的是梅肤,Message的UILable在alertView.subviews里面是第3個元素,第一個元素是一個UIImageView(背景),UILable(標題),UILable(Message),UIButton(Cancel)...(如果還有的話以此類推)邑茄。
5.ios后臺模式播放(鎖屏播放實現(xiàn))
音頻后臺播放,最開始集成是直接用beginReceivingRemoteControlEvents,并在kvo實現(xiàn)了,對應(yīng)方法.
但是在ios11無效果. 需要MPRemoteCommandCenter控制后臺中心去實現(xiàn)后臺控制,MPNowPlayingInfoCenter實現(xiàn)鎖屏后的界面展示.
即相應(yīng)實現(xiàn)API即可.