開發中 ios 11.0系統遇到的坑及解決辦法
導讀: 之前更新iOS11.0系統後,發現原來的專案有很多變化,例如,app的圖示不顯示了,tableview的佈局變了,搜尋框的樣式也有所變化,因此,針對這些問題找到了相應的解決方案。
一、app的圖示不顯示
原因:圖示不顯示主要是cocoaPod出現了問題
解決方案:使用命令列
第一步在PodFile中新增
post_install do |installer|
copy_pods_resources_path = “Pods/Target Support Files/Pods-專案名/Pods-專案名-resources.sh”
string_to_replace = ‘–compile “
assets_compile_with_app_icon_arguments = ‘–compile “
text = File.read(copy_pods_resources_path)
new_contents = text.gsub(string_to_replace, assets_compile_with_app_icon_arguments)
File.open(copy_pods_resources_path, “w”) {|file| file.puts new_contents }
end
注意end不可缺,這end並不是PodFile中的end。 編輯完成後。執行pod install
第二步 修改resources.sh檔案
開啟resources.sh檔案 將下面的printf程式碼替換為下面的程式碼
printf “%s\0” “
重啟專案,處理完成
二、tableview因為分組導致距離頂部有空白
解決方案:
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
return nil;
}
注意:這裡前2個代理返回的高度只能是0.01,不能設定為0,設定為0無效。
三、tableview重新整理後頁面“亂跑”
這是由於系統更新後,專案中沒有使用estimateRowHeight屬性
在appdelegate.m檔案中,加上這幾句程式碼:
//可以通過以下方式禁用
if (@available(iOS 11.0, *)) {
UITableView.appearance.estimatedRowHeight = 0;
UITableView.appearance.estimatedSectionFooterHeight = 0;
UITableView.appearance.estimatedSectionHeaderHeight = 0;
}
四、UISearchController的搜尋框文字與圖示居左顯示
iOS11.0之前的搜尋框文字和圖示預設居中顯示,更新後就變成上圖。
在不考慮重寫的方法下
//加上這三句話
UIOffset offset = {THfloat(90),0};
_searchVC.searchBar.searchTextPositionAdjustment = offset;
self.definesPresentationContext = YES;
可以達到這種效果:
但是圖示的位置我暫時還不知道如何更改。