iOS 7.0 presentViewController 背景变黑的解决办法
来源:互联网 发布:sql server 月份差 编辑:程序博客网 时间:2024/05/07 18:35
问题:在做分享到第三方的时候,要弹出一个分享框,底部的背景会变暗。在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即可。
- iOS 7.0 presentViewController 背景变黑的解决办法
- Android的listview滚动时背景不让变黑解决办法
- 关于presentViewController的后的background变黑的问题
- 关于presentViewController的后的background变黑的问题
- 关于presentViewController的后的background变黑的问题
- presentViewController的后的background变黑的问题
- Android listview在滚动的时候部分背景会变黑与cacheColorHint有关的解决办法
- IOS8以上或以下 presentViewController 背景不透明解决办法
- listview拖动时背景变黑的问题
- ListView 拖动的时候背景变黑
- ListView滚动时,背景变黑的解决方法
- listview拖动时背景变黑的问题
- listview拖动时背景变黑的问题
- listview解决拖动背景变黑的情况
- listview滚动时背景变黑的解决方法
- listview解决拖动背景变黑的情况
- ListView拖动时背景变黑的问题
- ListView 自定义背景后,滚动时的背景变黑问题
- iOS画圆角矩形的方法
- Gson的具体使用总结
- 跑马灯
- 常见的UIWDT bug分析案例(1)
- 字符串中空格用%20代替
- iOS 7.0 presentViewController 背景变黑的解决办法
- STL——for_each的用法
- Mybatis批量查询和模糊查询
- 【SPOJ-MYQ5】The Nerd Factor【计数DP】
- struts2的ActionSupport里面有execute
- ps切图(8)——精准切图
- 低位优先的字符串排序
- 关于Block代码块的使用
- 一:java传统线程创建