首页 > 其他 > 详细

关于presentViewController的后的background变黑的问题

时间:2014-08-05 22:41:00      阅读:559      评论:0      收藏:0      [点我收藏+]

先看一下效果图:

bubuko.com,布布扣

用如下代码,想弹出一个模态窗口,设置它的背景透明度为0.5,却发觉prsent后的背景色变为黑色的。

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实现:

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) {
 
}];
 
}

bubuko.com,布布扣

关于presentViewController的后的background变黑的问题,布布扣,bubuko.com

关于presentViewController的后的background变黑的问题

原文:http://blog.csdn.net/chaoyuan899/article/details/38390507

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!