新增的 cmd + 左鍵 彈出菜單個人感覺很多余,想要改回原來直接跳轉(zhuǎn)的同學(xué)可以在 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修改了它們的默認(rèn)值,全部變成默認(rèn)開啟的狀態(tài)。
這個修改產(chǎn)生了下面的問題
- UITableViewStyleGrouped樣式的UITableView的sectionHeader和sectionFooter有一個默認(rèn)的高度,通常不需要顯示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,保證你的內(nèi)容不覆蓋住狀態(tài)欄。
但是之前寫的時候想必已經(jīng)考慮到這20px了,于是你的ScrollView突然多了20px的偏移,影響大小要看具體情況,當(dāng)然最好是直接關(guān)掉這個特性
_list.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
iOS 11 下會自動給 frame 觸及到safeArea 的scrollView 添加一個單獨的 safeAreaInsets,inset 上部默認(rèn) 44px(iPhone X為例),有 navigationBar 的情況下是 88px(注:如果設(shè)置 navigationBar.hidden = YES,上部會變成 44px),底部則是34 px,多數(shù)情況下直接把 scrollView 鋪滿屏幕即可,或者關(guān)閉 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;
}
}
- 調(diào)試發(fā)現(xiàn)tableView在某些情況下會用默認(rèn)的cell高度(44px)去修正contentInset,例如top + bottom + contentSize計算出來的列表高度小于自己frame的時候。
修正contentInset也會造成contentOffset的變動,我的頁面有很多其他的視圖和contentOffset有關(guān),直接導(dǎo)致整個頁面都亂了。
這里和1相同,需要設(shè)置_list.estimatedRowHeight = 0
綜上,如果沒有用自動計算高度的習(xí)慣,推薦直接 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