iOS13測試版已經(jīng)發(fā)布了,寡人嘗試了一波更新,發(fā)現(xiàn)了一些問題咱筛,一下列出寡人遇到的問題與解決辦法彼妻,可能不全嫌佑,待補(bǔ)充
自定義導(dǎo)航欄
/* 自定義導(dǎo)航欄 */
UINavigationBarAppearance * costomNavBar = [[UINavigationBarAppearance alloc] init];
/* 導(dǎo)航需要的富文本設(shè)置 可寫成2個,一個標(biāo)準(zhǔn)的侨歉,一個大字體的 */
NSDictionary *attrDict = @{ NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName: [UIColor blueColor] };
/* 標(biāo)準(zhǔn)字體的 富文本 */
costomNavBar.titleTextAttributes = attrDict;
/* 大標(biāo)題 */
costomNavBar.largeTitleTextAttributes = attrDict;
/* 設(shè)置普通自定義導(dǎo)航條 */
nav.navigationBar.standardAppearance = costomNavBar;
/* 緊湊高度導(dǎo)航欄外觀設(shè)置 */
nav.navigationBar.compactAppearance = costomNavBar;
/* 是否顯示大標(biāo)題 */
nav.navigationBar.prefersLargeTitles = YES;
/* 滾到頭時 導(dǎo)航顯示 */
nav.navigationBar.scrollEdgeAppearance = costomNavBar;
Search
1.Search TextFiled
- (void)setShowsScopeBar:(BOOL)show animated:(BOOL)animate;
新屬性: searchTextField
注意:iOS 13 以后不能使用 KVC 方法獲取 輸入框的UITextField屋摇,會崩潰
代碼示例: UITextField * searchField = [_searchBar valueForKey:@"_searchField"];
應(yīng)改為 _searchBar. searchTextField;
新增代理:UISearchTextFieldDelegate
//通過 searchToken(新增標(biāo)識) 搜索
- searchTextField:itemProviderForCopyingToken:
2.Search Token
UISearchToken * token = [UISearchToken tokenWithIcon:[UIImage imageNamed:@"旺旺"] text:@"喵了個咪"];
presentViewController
兼容問題:
- presentViewController彈出的帶導(dǎo)航的控制器如果采用 top,bottom 這種幽邓,會出現(xiàn)視圖距離導(dǎo)航偏差問題炮温,因為它不再從 (0,0)布局了
建議宏定義 self.navigationController.navigationBar.maxY 從導(dǎo)航條下布局
2.dismiss VC 后牵舵,不再走 View 生命周期方法
- (void)viewWillAppear:(BOOL)animated柒啤;
- (void)viewWillDisappear:(BOOL)animated;
如果在該方法設(shè)置初始化事件畸颅,請注意該問題
注意:如果不想要這種【小卡片】式彈出可以修改 .modalPresentationStyle
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:testVC];
testVC.modalPresentationStyle = UIModalPresentationFullScreen;
/* 如果還是不行担巩,請嘗試修改導(dǎo)航的 modalPresentationStyle*/
[self presentViewController:nav animated:YES completion:nil];
另外,UIViewController 增加一個了屬性 isModalInPresentation没炒,默認(rèn)為 false涛癌,當(dāng)該屬性為 false 時,用戶下拉可以 dismiss 控制器送火,為 true 時拳话,下拉不可以 dismiss控制器。該屬性可以配合有編輯功能的控制器使用
DeviceToken
#include <arpa/inet.h> //(友盟提供)
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
if (![deviceToken isKindOfClass:[NSData class]]) return;
const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
NSLog(@"deviceToken:%@",hexToken);
}
Window
初始化:
在 SceneDelegate 的 willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions 方法中 初始化窗口
UIWindowScene * windowScene = [[UIWindowScene alloc] initWithSession:session connectionOptions:connectionOptions];
_window = [[UIWindow alloc] initWithWindowScene:windowScene];
UIWindowScene 是管理應(yīng)用程序的一個或多個窗口的特定類型的對象漾脂,有以下屬性:
windows 假颇, screen 窗口的一些東西
//描述場景當(dāng)前環(huán)境的特征,例如大小等級和比例因子
@property(nonatomic, readonly) UITraitCollection *traitCollection;
//方向骨稿,你懂得
@property(nonatomic, readonly) UIInterfaceOrientation interfaceOrientation;
//狀態(tài)欄當(dāng)前配置
@property(nonatomic, readonly) UIStatusBarManager *statusBarManager;
還要說下這個 可以去官網(wǎng)看下
//用于管理場景中發(fā)生的特定于應(yīng)用程序的任務(wù)的其他方法
@protocol UIWindowSceneDelegate
//用于響應(yīng)場景中發(fā)生的生命周期事件的核心方法笨鸡。
@protocol UISceneDelegate
其他屬性修改:
官方不再推薦使用 keywindow 屬性
Dark Mode 暗模式
用Any Appearance變量指定要在不支持暗模式的舊系統(tǒng)上使用的顏色值
兼容問題:
1.沒有設(shè)置背景色的 都變成 黑色了
2.XIb 設(shè)置的黑色 字體姜钳,在該模式下變成白色了,然而我背景卻是白色的形耗,這樣
就感覺字消失了,原因是 xib 字體顏色為 【label color】這是新增的 顏色屬性哥桥,(詳情看下邊的UIColor)改為你想要的顏色
蘋果解釋:https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/#dynamic-system-colors
如果想讓APP保持原狀態(tài) plist 設(shè)置:
UIColor
Label 顏色
/* 包含主要內(nèi)容的文本標(biāo)簽的顏色 */
@property(class, nonatomic, readonly) UIColor *labelColor;
/* 包含輔助內(nèi)容的文本標(biāo)簽的顏色 */
@property(class, nonatomic, readonly) UIColor *secondaryLabelColor;
/* 包含第三級內(nèi)容的文本標(biāo)簽的顏色 */
@property(class, nonatomic, readonly) UIColor *tertiaryLabelColor;
/* 包含四元內(nèi)容的文本標(biāo)簽的顏色 */
@property(class, nonatomic, readonly) UIColor *quaternaryLabelColor;
填充色
填充色 系統(tǒng)填充顏色包含透明度,以允許顯示背景顏色
/* 系統(tǒng)填充色 */
@property(class, nonatomic, readonly) UIColor *systemFillColor激涤;
/* 使用此顏色填充中等大小的形狀拟糕,例如開關(guān)的背景 */
@property(class, nonatomic, readonly) UIColor *secondarySystemFillColor;
/* 使用此顏色填充大型形狀,例如輸入字段倦踢,搜索欄或按鈕 */
@property(class, nonatomic, readonly) UIColor *tertiarySystemFillColor;
/* 使用此顏色填充包含復(fù)雜內(nèi)容的大區(qū)域送滞,例如展開的表格單元格。 */
@property(class, nonatomic, readonly) UIColor *quaternarySystemFillColor;
其他
不一一列舉了辱挥,有點多犁嗅,寫幾個以后會常用的吧
/* 這啥顏色我也不想復(fù)制了,你懂得 */
@property(class, nonatomic, readonly) UIColor *placeholderTextColor;
/* 分割線顏色 */
@property(class, nonatomic, readonly) UIColor *separatorColor;
/* 隱藏任何基礎(chǔ)內(nèi)容的邊框或分隔線的顏色 */
@property(class, nonatomic, readonly) UIColor *opaqueSeparatorColor;
/* 連接顏色 */
@property(class, nonatomic, readonly) UIColor *linkColor;
******************* 崩潰信息 *******************
注意:當(dāng)前版本是測試版,只是給各位個參考晤碘,但不一定準(zhǔn)確褂微,具體要根據(jù)你的代碼搞一搞
1.[_LSDefaults sharedInstance]: unrecognized selector sent to class 0x1df510dd8
定位:友盟統(tǒng)計 注冊 key 時會報錯,應(yīng)該是不兼容問題园爷,估計以后 友盟會更新兼容庫
2. UITextField * searchField = [_searchBar valueForKey:@"_searchField"];斷點指示崩潰
修改: _searchBar. searchTextField; 上邊有注