新增的 cmd + 左鍵 彈出菜單個人感覺很多余锋谐,想要改回原來直接跳轉的同學可以在 Preferences - Navigation - Command-click on Code 改成 Jumps to Definition
Xcode9 warning :'xxx' is partial: introduced in iOS 10.0
Xcode9里面OC代碼也支持swift的@available
了,不再需要去寫一串[[[UIDevice currentDevice] systemVersion] floatValue]
帮掉,在函數(shù)里面可以這么寫
if (@available(iOS 10.0, *)) {
}
else {
}
然而現(xiàn)在并不能用爹耗,Xcode9打的包不能提交給Apple審核
另外用Xcode9打開原有代碼時千所,下面的代碼提示了'NCWidgetDisplayMode' is partial: introduced in iOS 10.0
- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize {
if (activeDisplayMode == NCWidgetDisplayModeCompact) {
self.preferredContentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 110);
} else {
self.preferredContentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 300);
}
}
在函數(shù)聲明的時候不能使用@available
枷邪,在SO查了一下,最后面加上NS_AVAILABLE_IOS(10_0)
就可以消除這個warning
UITableView in iOS11
@property (nonatomic) CGFloat estimatedRowHeight NS_AVAILABLE_IOS(7_0); // default is UITableViewAutomaticDimension, set to 0 to disable
@property (nonatomic) CGFloat estimatedSectionHeaderHeight NS_AVAILABLE_IOS(7_0); // default is UITableViewAutomaticDimension, set to 0 to disable
@property (nonatomic) CGFloat estimatedSectionFooterHeight NS_AVAILABLE_IOS(7_0); // default is UITableViewAutomaticDimension, set to 0 to disable
這三個屬性是iOS7加入的吮播,但是iOS11修改了它們的默認值,全部變成默認開啟的狀態(tài)眼俊。
這個修改產生了下面的問題
- UITableViewStyleGrouped樣式的UITableView的sectionHeader和sectionFooter有一個默認的高度意狠,通常不需要顯示header或者footer的時候,會這么寫
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
但是在iOS11里面你會發(fā)現(xiàn)段頭段尾又回來辣疮胖!改了各種新增的屬性比如safeArea之類的一點用都沒有环戈,最后發(fā)現(xiàn)必須要把estimatedSectionHeaderHeight置0才變回去
safeArea引起的contentInset誤差:一個全屏Frame的scrollView,iOS11會貼心地幫你在頭部添加20px的contentInset澎灸,保證你的內容不覆蓋住狀態(tài)欄院塞。
但是之前寫的時候想必已經考慮到這20px了,于是你的ScrollView突然多了20px的偏移性昭,影響大小要看具體情況迫悠,當然最好是直接關掉這個特性
_list.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
iOS 11 下會自動給 frame 觸及到safeArea 的scrollView 添加一個單獨的 safeAreaInsets,inset 上部默認 44px(iPhone X為例)巩梢,有 navigationBar 的情況下是 88px(注:如果設置 navigationBar.hidden = YES,上部會變成 44px),底部則是34 px艺玲,多數(shù)情況下直接把 scrollView 鋪滿屏幕即可括蝠,或者關閉 scrollView 的 contentInsetAdjustmentBehavior,單獨處理饭聚。
但是有時候有需要配合底部工具欄(UIToolBar 會自動適配)忌警,那么需要對不同機型適配 safeArea ,iPhone X (44秒梳, 0法绵, 34, 0)酪碘,其余機型(20朋譬, 0, 0兴垦, 0)徙赢,這個 UIEdgeInset 可以用下面的代碼獲取
// 需要 Xcode 9
- (UIEdgeInsets)safeAreaInset {
if (@available(iOS 11.0, *)) {
return [UIApplication sharedApplication].keyWindow.safeAreaInsets;
}
else {
return UIEdgeInsetsZero;
}
}
- 調試發(fā)現(xiàn)tableView在某些情況下會用默認的cell高度(44px)去修正contentInset字柠,例如top + bottom + contentSize計算出來的列表高度小于自己frame的時候。
修正contentInset也會造成contentOffset的變動狡赐,我的頁面有很多其他的視圖和contentOffset有關窑业,直接導致整個頁面都亂了。
這里和1相同枕屉,需要設置_list.estimatedRowHeight = 0
綜上常柄,如果沒有用自動計算高度的習慣,推薦直接 hook 掉這三個屬性
@implementation UITableView (DisableEstimateHeight)
+ (void)load
{
Method newMethod = class_getInstanceMethod([UITableView class], @selector(hook_initWithFrame:style:));
Method originMethod = class_getInstanceMethod([UITableView class], @selector(initWithFrame:style:));
method_exchangeImplementations(newMethod, originMethod);
}
- (instancetype)hook_initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
UITableView *tableView = [self hook_initWithFrame:frame style:style];
tableView.estimatedRowHeight = 0;
tableView.estimatedSectionFooterHeight = 0;
tableView.estimatedSectionHeaderHeight = 0;
return tableView;
}
@end