iOS13中presentViewController的问题
程序员文章站
2022-04-09 15:59:17
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];
文章若有不对地方,欢迎批评指正