设置 modalPresentationStyle
let mainViewController = UIView() // 即需要被present的view
mainViewController.modalPresentationStyle = .fullScreen
self.present(mainViewController, animated: true, completion: nil)
UIViewController *vc1 = [[UIViewController alloc] init]; // vc1即需要被present的viewcontroller
vc1.modalPresentationStyle = 0;
[self presentViewController:vc animated:YES completion:nil];
presentViewController 半透明 变黑
MSTestViewController *vc = [[MSTestViewController alloc] init];
vc.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
float version = [UIDevice currentDevice].systemVersion.floatValue;
if (version < 8.0) { // iOS 7 实现的方式略有不同(设置self)
self.modalPresentationStyle = UIModalPresentationCurrentContext;
// iOS8以下必须使用rootViewController,否则背景会变黑
[self.view.window.rootViewController presentViewController:vc animated:YES completion:^{
}];
} else { // iOS 8 以上实现(设置vc)
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext|UIModalPresentationFullScreen;
//如果控制器属于navigationcontroller或者tababrControlelr子控制器,不使用UIModalPresentationFullScreen 的话, bar 会盖住你的modal出来的控制器
[self presentViewController:vc animated:YES completion:^{
// 也可以在这里做一些完成modal后需要做得事情
}];
}
https://www.jianshu.com/p/4f96d078f1f3
https://www.jianshu.com/p/4cd8df54ed0d
网友评论