我试图在另一个视图控制器上展示一个视图控制器,在这个控制器上将是透明的,并且底部会有这种模糊的效果。
所发生的是,我看到一个黑色的背景在呈现的视图,虽然它的清晰的颜色。
我也在这里读过,并且做了完全一样的事情:Display clearColor UIViewController over UIViewController
//to present
PillView *pillv=[[PillView alloc]initWithPill:pill WithNum:num];
pillv.delegate=self;
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualEffectView;
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame=CGRectMake(0, 0, self.view.frame.size.width, [Globals sharedGlobals].titleHeight*self.view.frame.size.height);
[self.view addSubview:visualEffectView];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:pillv animated:NO completion:nil];
发布于 2015-10-22 04:51:57
您需要将UIVisualEffectView
添加到呈现视图控制器,而不是正在进行演示的视图控制器。
PillView *pillv=[[PillView alloc]initWithPill:pill WithNum:num];
pillv.delegate=self;
UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame= pillv.view.bounds;
pillv.view.backgroundColor = [UIColor clearColor];
[pillv.view insertSubview:visualEffectView atIndex:0];
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:pillv animated:NO completion:nil];
而且,由于OP似乎认为我的解决方案不起作用,下面是一个示例项目来说明这一点:
https://dl.dropboxusercontent.com/u/29456419/blurTest.zip
下面是视图(呈现)和OverlayView的图片:
发布于 2015-10-22 05:13:43
在Ios 8及以上版本,请使用UIModalPresentationOverCurrentContext而不是UIModalPresentationCurrentContext
发布于 2015-10-22 05:18:02
如果在UIModalPresentationOverCurrentContext
或更高版本上表示样式,请使用iOS8。
但是,关键设置是,对于希望显示的呈现控制器,需要将definesPresentationContext
设置为true。
从文件中:
UIModalPresentationOverCurrentContext 在视图控制器的内容上显示内容的一种表示样式,其definesPresentationContext属性为YES。UIKit可以沿着视图控制器层次结构来查找想要定义表示上下文的视图控制器。当演示文稿结束时,显示内容下的视图不会从视图层次结构中移除。因此,如果呈现的视图控制器没有用不透明的内容填充屏幕,则底层内容将显示出来。 当在弹出器中显示视图控制器时,只有当转换样式为UIModalTransitionStyleCoverVertical时,才支持此表示样式。尝试使用不同的转换样式会触发异常。但是,如果父视图控制器不在弹出窗口中,则可以使用其他转换样式(部分卷曲转换除外)。 可在iOS 8.0及更高版本中获得。
所以:
self.definesPresentationContext = true
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:pillv animated:NO completion:nil];
https://stackoverflow.com/questions/33281273
复制相似问题