iOS13中presentViewController的問題 更新了Xcode11.0 beta之後,在iOS13中運行代碼發現 和之前彈出的樣式不一樣。 會出現這種情況是主要是因為我們之前對 裡面的一個屬性,即 (該屬性是控制器在模態視圖時將要使用的樣式)沒有設置需要的類型。在iOS13中 的預設 ...
iOS13中presentViewController的問題
更新了Xcode11.0 beta之後,在iOS13中運行代碼發現presentViewController
和之前彈出的樣式不一樣。
會出現這種情況是主要是因為我們之前對UIViewController
裡面的一個屬性,即modalPresentationStyle
(該屬性是控制器在模態視圖時將要使用的樣式)沒有設置需要的類型。在iOS13中modalPresentationStyle
的預設改為UIModalPresentationAutomatic
,而在之前預設是UIModalPresentationFullScreen
。
/*
Defines the presentation style that will be used for this view controller when it is presented modally. Set this property on the view controller to be presented, not the presenter.
If this property has been set to UIModalPresentationAutomatic, reading it will always return a concrete presentation style. By default UIViewController resolves UIModalPresentationAutomatic to UIModalPresentationPageSheet, but other system-provided view controllers may resolve UIModalPresentationAutomatic to other concrete presentation styles.
Defaults to UIModalPresentationAutomatic on iOS starting in iOS 13.0, and UIModalPresentationFullScreen on previous versions. Defaults to UIModalPresentationFullScreen on all other platforms.
*/
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle API_AVAILABLE(ios(3.2));
要改會原來模態視圖樣式,我們只需要把UIModalPresentationStyle
設置為UIModalPresentationFullScreen
即可。
ViewController *vc = [[ViewController alloc] init];
vc.title = @"presentVC";
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:nav animated:YES completion:nil];
私有KVC
在使用iOS 13運行項目時突然APP就crash
掉了。定位到的問題是在設置UITextField
的Placeholder
也就是占位文本的顏色和字體時使用了KVC的方法:
[_textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
[_textField setValue:[UIFont systemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];
可以將其替換為
_textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"姓名" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor redColor]}];
並且只需要在初始化的時候設置attributedPlaceholder
即富文本的占位文本,再重新賦值依然使用placeolder
直接設置文本內容,樣式不會改變。
持續更新中·····
文章若有不對地方,歡迎批評指正