在iOS13中使用presentViewController的时候,页面顶部会空出一部分来。

原因是因为UIViewController的一个属性modalPresentationStyle
/*
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 system-provided subclasses may resolve UIModalPresentationAutomatic to other concrete presentation styles. Participation in the resolution of UIModalPresentationAutomatic is reserved for system-provided view controllers.
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));
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
UIModalPresentationFullScreen = 0,
UIModalPresentationPageSheet API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos),
UIModalPresentationFormSheet API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos),
UIModalPresentationCurrentContext API_AVAILABLE(ios(3.2)),
UIModalPresentationCustom API_AVAILABLE(ios(7.0)),
UIModalPresentationOverFullScreen API_AVAILABLE(ios(8.0)),
UIModalPresentationOverCurrentContext API_AVAILABLE(ios(8.0)),
UIModalPresentationPopover API_AVAILABLE(ios(8.0)) API_UNAVAILABLE(tvos),
UIModalPresentationBlurOverFullScreen API_AVAILABLE(tvos(11.0)) API_UNAVAILABLE(ios) API_UNAVAILABLE(watchos),
UIModalPresentationNone API_AVAILABLE(ios(7.0)) = -1,
UIModalPresentationAutomatic API_AVAILABLE(ios(13.0)) = -2,
};
在iOS13中,modalPresentationStyle的默认值是UIModalPresentationAutomatic,而在iOS12以下的版本,默认值是UIModalPresentationFullScreen,这就导致了在iOS13中present出来的页面没法全屏。
可以在presentViewController的时候设置controller为全屏样式。
ImageDisplayViewController *ctrl = [[ImageDisplayViewController alloc] init];
ctrl.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:ctrl animated:YES completion:nil];
在iOS13中,由于UIViewController的modalPresentationStyle属性默认值更改为UIModalPresentationAutomatic,这可能导致presentViewController呈现的视图无法全屏。解决办法是在调用前设置modalPresentationStyle为UIModalPresentationFullScreen。
4921

被折叠的 条评论
为什么被折叠?



