如何Present一个半透明的UIViewController控制器

网上看了很多关于这方面的博客,写的都不是很清楚,发现现在网上很多关于iOS的技术博客内容质量都很低,或者内容已过时。
推出一个半透明控制器iOS8之前和之后不太一样,详细请参考如下代码,很简单

UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *presentedVC = [[UIViewController alloc] init];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
      // presentedVC 为被弹出的控制器
      presentedVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
 } else {
      // rootVC 为window的rootViewController
      rootVC.modalPresentationStyle = UIModalPresentationCurrentContext;
 }
    presentedVC.view.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.7];
     // self 为当前控制器
    [self presentViewController:presentedVC animated:YES completion:nil];

Update 161121

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容