关于presentViewController的后的background变黑的问题
2015-11-07 02:11
435 查看
转载自:http://blog.csdn.net/chaoyuan899/article/details/38390507
iospresentViewControllepushViewControllerbackgound变黑UIColor
目录(?)[+]
先看一下效果图:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201511/706c7f7cca6723c83c04ff0c931a7e59)
用如下代码,想弹出一个模态窗口,设置它的背景透明度为0.5,却发觉prsent后的背景色变为黑色的。
[objc] view
plaincopyprint?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
ShareVC *share = [[ShareVC alloc] init];
[self presentViewController:share animated:YES completion:nil];
起初还以为是设置透明度或者是[UIColor clearColor]出的问题,鼓捣几次之后发现不是这个问题。google之后,在stackOverflow上找到几个比较靠谱的答案~
最终结论为:
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.
所以还是改用为UIView Animations实现:
[objc] view
plaincopyprint?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
if (!_isShareViewOpen) {
_isShareViewOpen = YES;
ShareVC *shareVC = [[ShareVC alloc] initWithNibName:@"ShareVC" bundle:nil];
shareVC.shareVC = shareVC;
shareVC.awardList = self;
[self.view addSubview:shareVC.view];
[UIView animateWithDuration:0.75f animations:^{
shareVC.view.frame = CGRectMake(0, 640, self.view.frame.size.width, self.view.frame.size.height);
shareVC.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
}];
}
![](https://oscdn.geek-share.com/Uploads/Images/Content/201511/28b2df77b05fe88a8a0d34fc8049a04c)
--------------------------------------------------------------------------2014.09.26 再次编辑 ------------------------------------------------------------------
如果你不想用动画来实现 present 的效果,可以设置 presentViewController 的属性,一样可以达到以上效果:
[objc] view
plaincopyprint?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
presentingViewController.modalPresentationStyle = <span style="font-family: Arial, Helvetica, sans-serif;">UIModalPresentationCurrentContext</span>;
--------------------------------------------------------------------------2015.01.22 再次编辑 ------------------------------------------------------------------
以上代码只是在 IOS7 中起作用,到 IOS8 就没用了,IOS8 可以用以下代码 fix:
[objc] view
plaincopyprint?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
_imagePickerCtrl.modalPresentationStyle = UIModalPresentationOverCurrentContext;
_imagePickerCtrl.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[appViews.rootViewController presentViewController:_imagePickerCtrl animated:YES completion:nil];
![](https://oscdn.geek-share.com/Uploads/Images/Content/201511/a081de42c06e444d6dd909a7643f1794)
参考链接:http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=18661
版权声明:本文为博主原创文章,未经博主允许不得转载。
iospresentViewControllepushViewControllerbackgound变黑UIColor
目录(?)[+]
先看一下效果图:
用如下代码,想弹出一个模态窗口,设置它的背景透明度为0.5,却发觉prsent后的背景色变为黑色的。
[objc] view
plaincopyprint?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
ShareVC *share = [[ShareVC alloc] init];
[self presentViewController:share animated:YES completion:nil];
起初还以为是设置透明度或者是[UIColor clearColor]出的问题,鼓捣几次之后发现不是这个问题。google之后,在stackOverflow上找到几个比较靠谱的答案~
Why
Does presentModalViewController:animated: Turn The Background Black?
Display
clearColor UIViewController over UIViewController
最终结论为: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.
所以还是改用为UIView Animations实现:
[objc] view
plaincopyprint?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
if (!_isShareViewOpen) {
_isShareViewOpen = YES;
ShareVC *shareVC = [[ShareVC alloc] initWithNibName:@"ShareVC" bundle:nil];
shareVC.shareVC = shareVC;
shareVC.awardList = self;
[self.view addSubview:shareVC.view];
[UIView animateWithDuration:0.75f animations:^{
shareVC.view.frame = CGRectMake(0, 640, self.view.frame.size.width, self.view.frame.size.height);
shareVC.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
}];
}
--------------------------------------------------------------------------2014.09.26 再次编辑 ------------------------------------------------------------------
如果你不想用动画来实现 present 的效果,可以设置 presentViewController 的属性,一样可以达到以上效果:
[objc] view
plaincopyprint?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
presentingViewController.modalPresentationStyle = <span style="font-family: Arial, Helvetica, sans-serif;">UIModalPresentationCurrentContext</span>;
--------------------------------------------------------------------------2015.01.22 再次编辑 ------------------------------------------------------------------
以上代码只是在 IOS7 中起作用,到 IOS8 就没用了,IOS8 可以用以下代码 fix:
[objc] view
plaincopyprint?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
_imagePickerCtrl.modalPresentationStyle = UIModalPresentationOverCurrentContext;
_imagePickerCtrl.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[appViews.rootViewController presentViewController:_imagePickerCtrl animated:YES completion:nil];
参考链接:http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=18661
版权声明:本文为博主原创文章,未经博主允许不得转载。
相关文章推荐
- springmvc的Ajax提交问题
- Foundation框架- NSString用法
- oc必须知道的知识点
- Mysql学习笔记
- jenkins构建war失败 代码编译出现(illegal character: \65279)
- MySQL5.1 忘记root密码的解决方法
- 雅虎十四条:网站前端网页优化的14条原则
- 基因芯片和NGS的关系
- 微软远程桌面(安卓版)连接出现0x204错误的解决办法
- linux 系统调用sysconf函数使用
- poj 1222 高斯消元(改改模板)
- 黑马程序员——类加载器——委托机制、自定义类加载器
- Ubuntu安装Anaconda3
- 夺命雷公狗ThinkPHP项目之----商城7后台登录控制以及注销
- 面向对象
- 大数模板
- Android使用.9图片失效的问题
- 集成支付宝、
- 10004---JavaWEB基础--HTTP,POST,GET
- mac 下svn 代码迁移到git