您的位置:首页 > 其它

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

2015-11-07 02:11 435 查看
转载自:http://blog.csdn.net/chaoyuan899/article/details/38390507

iospresentViewControllepushViewControllerbackgound变黑UIColor

目录(?)[+]

先看一下效果图:



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

[objc] view
plaincopyprint?





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?





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?





presentingViewController.modalPresentationStyle = <span style="font-family: Arial, Helvetica, sans-serif;">UIModalPresentationCurrentContext</span>;

--------------------------------------------------------------------------2015.01.22 再次编辑 ------------------------------------------------------------------

以上代码只是在 IOS7 中起作用,到 IOS8 就没用了,IOS8 可以用以下代码 fix:

[objc] view
plaincopyprint?





_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

版权声明:本文为博主原创文章,未经博主允许不得转载。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: