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];
文章若有不對地方,歡迎批評指正