在iOS 13中,模态视图控制器在呈现时有一个新的行为。
现在它不是全屏默认情况下,当我向下滑动时,应用会自动解除视图控制器。
我怎么能防止这种行为,并回到旧的全屏模态vc?
谢谢
在iOS 13中,模态视图控制器在呈现时有一个新的行为。
现在它不是全屏默认情况下,当我向下滑动时,应用会自动解除视图控制器。
我怎么能防止这种行为,并回到旧的全屏模态vc?
谢谢
当前回答
对于Objective-C用户
只需使用这段代码
[vc setModalPresentationStyle: UIModalPresentationFullScreen];
或者如果你想在iOS 13.0中添加它,那么使用
if (@available(iOS 13.0, *)) {
[vc setModalPresentationStyle: UIModalPresentationFullScreen];
} else {
// Fallback on earlier versions
}
其他回答
let Obj = MtViewController()
Obj.modalPresentationStyle = .overFullScreen
self.present(Obj, animated: true, completion: nil)
//如果你想禁用滑动来消除它,添加行
Obj.isModalInPresentation = true
查看苹果文档获取更多信息。
这里有一个简单的解决方案,无需编写任何代码。
在故事板中选择视图控制器 选择属性检查器 按照下图将显示“自动”设置为“全屏”
这一变化使iPad应用程序的行为符合预期,否则新屏幕将以弹出窗口的形式显示在屏幕中央。
为UIViewController创建一个类别(比如UIViewController+PresentationStyle)。向其添加以下代码。
-(UIModalPresentationStyle)modalPresentationStyle{
return UIModalPresentationStyleFullScreen;
}
所有其他答案都足够了,但对于像我们这样的大型项目,导航是在代码和故事板中完成的,这是一项相当艰巨的任务。
对于那些积极使用Storyboard的人。这是我的建议:使用正则表达式。
以下格式不适用于全屏页面:
<segue destination="Bof-iQ-svK" kind="presentation" identifier="importSystem" modalPresentationStyle="fullScreen" id="bfy-FP-mlc"/>
以下格式适用于全屏页面:
<segue destination="7DQ-Kj-yFD" kind="presentation" identifier="defaultLandingToSystemInfo" modalPresentationStyle="fullScreen" id="Mjn-t2-yxe"/>
以下与VS CODE兼容的正则表达式将所有旧样式页面转换为新样式页面。如果您正在使用其他正则表达式引擎/文本编辑器,则可能需要转义特殊字符。
搜索正则表达式
<segue destination="(.*)"\s* kind="show" identifier="(.*)" id="(.*)"/>
正则表达式替换
<segue destination="$1" kind="presentation" identifier="$2" modalPresentationStyle="fullScreen" id="$3"/>
下面是Objective-C的解决方案
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"ViewController"];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:vc animated:YES completion:nil];