最近手机升级iOS13后,运行程序发现了一个问题。调用presentViewController的时候,页面无法全屏显示,顶部会有一些空白。
查了下发现是presentViewController的页面展示默认方式有所变更。presentViewController是通过modalPresentationStyle这个属性来设置展示形式的。定义如下:
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以前默认使用的是UIModalPresentationFullScreen,现在默认使用的是UIModalPresentationAutomatic。
添加一句语句就可以正常显示全屏了:
UIViewController *appViewController = [[UIViewController alloc] init];
appViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:appViewController animated:NO completion:nil] ;