当前位置: 首页 > news >正文

iOS 7.0 presentViewController 背景变黑的解决办法

问题在做分享到第三方的时候,要弹出一个分享框,底部的背景会变暗。在iOS8.0以上可以直接设置,但在iOS8.0以下会出现背景变黑的情况。


原因分析:Why Does presentModalViewController:animated: Turn The Background Black?

                    Display clearColor UIViewController over UIViewController

找到原因:    (界面同一时刻只能展示一个View Controller)

NavigationController and the View Controllers are designed in such a way that only one view controller may show at a time. When a new view controller is pushed/presented the previous view controller will be hidden by the system. So when you reduce the modal view's alpha you will possibly see the window's backgroundColor (the black color you see now).

If you want a translucent view to slide-in over the main view, you can add the view as the subView of main view and animate it using UIView Animations.

解决办法: iOS7.0时在弹出分享的界面的时候截取当前屏幕的图片,然后在弹出分享的界面之后将图片的ImageView添加在分享控制器的视图下(index = 0)。

//展示分享的控制器
-(void)presentShareViewController:(UIViewController*)controller{if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {controller.modalPresentationStyle = UIModalPresentationOverCurrentContext;[self presentViewController:controller animated:YES completion:nil];}else if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){UIImageView *bottomImageView = [self getBottomImageView];controller.modalPresentationStyle = UIModalPresentationCurrentContext;[self presentViewController:controller animated:YES completion:^{[controller.view insertSubview:bottomImageView atIndex:0];}];}
}//获取添加在controller.view上的ImageView
-(UIImageView*)getBottomImageView{UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);[[[UIApplication sharedApplication] keyWindow].layer renderInContext:UIGraphicsGetCurrentContext()];UIImage * img = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();UIImageView *bottomImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];bottomImageView.userInteractionEnabled = YES;bottomImageView.alpha = 0.8;[bottomImageView setImage:img];return bottomImageView;
}

用法在展示分享控制器时,只要调用presentShareViewController即可。






http://www.xdnf.cn/news/853489.html

相关文章:

  • 开心网外挂开发手记
  • Rockchip | 使用SD卡启动或升级固件到本地存储
  • 世界顶级五大女程序媛,不仅技术强还都是美女
  • Windows的EXE文件(1)
  • 卡巴斯基KAV/KIS 6.0/7.0 永久免费激活方法
  • 怎么做英文外链代发
  • ThinkPad T41/43 -- 安装Windows XP及其驱动程序
  • Visual SourceSafe 6.0 安装配置简要说明(转)
  • 低格格式化过程及与高级格式化的区别
  • Joomla安装图文教程 (送 Joomla 中文语言包)
  • 3.4 DLL注入:全局消息钩子注入
  • CSS3 经典教程系列:CSS3 圆角(border-radius)详解
  • 网卡参数设置建议与各个网卡参数含义详解
  • cortex-a8原理实践及应用
  • 获取IP地址
  • java开源的cms系统jsp cms系统
  • 第四章 数据字典详解
  • Discuz论坛设置论坛版块横排后,如何设置显示版块图标
  • nero刻录错误 序列号问题
  • 如何破解XP开机密码
  • Discuz!6.0 升级至 Discuz!7.2
  • C++在线五子棋对战(网页版)项目:实用工具类模块代码实现
  • 主流WebService框架
  • 2021年月薪多少,才能在北上广深“体面”生活?
  • android视频播放器排行榜,安卓视频播放器哪个好 五款主流视频播放器对比
  • iOS开发 swift 3dTouch实现 附代码
  • 黑马点评项目学习笔记(15w字详解,堪称史上最详细,欢迎收藏)
  • 解决 IE 选项卡重启的问题(此选项卡已经恢复)(ZT)
  • 对日软件外包
  • 谢国忠观点