2
votes

I am trying to present a view controller over another one, where the upper will be transparent , and the bottom would have this blur effect.

What happened is that i see a black background in the presented view, although its clear colour.

I have also read here, and did exactly the same : 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];
3
are ou testing it with the simulator or the device?Julian
simulator , is there a problem with it ?Curnelious
checked also in device not working..Curnelious
so you want to make pillView transparent ?Teja Nandamuri
yes. it is transparent actually, i set its background to clearCurnelious

3 Answers

3
votes

From Ios 8 and upper please use UIModalPresentationOverCurrentContext instead of UIModalPresentationCurrentContext

2
votes

You need to add the UIVisualEffectView to the presented View Controller, and not the one that is doing the presentation.

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];

And because the OP seems to be thinking my solution is not working, here is a sample project to show this:

https://dl.dropboxusercontent.com/u/29456419/blurTest.zip

And here are the pictures of the view (presenting) and then the OverlayView:

Presenting ViewControllerOverlay ViewController

0
votes

Use UIModalPresentationOverCurrentContext for the presentation style if on iOS8 or higher.

However, the key setting is that you need to set definesPresentationContext to true for the presenting controller you wish to be seen showing through.

From the documentation:

UIModalPresentationOverCurrentContext

A presentation style where the content is displayed over a view controller’s content whose definesPresentationContext property is YES. UIKit may walk up the view controller hierarchy to find a view controller that wants to define the presentation context. The views beneath the presented content are not removed from the view hierarchy when the presentation finishes. So if the presented view controller does not fill the screen with opaque content, the underlying content shows through.

When presenting a view controller in a popover, this presentation style is supported only if the transition style is UIModalTransitionStyleCoverVertical. Attempting to use a different transition style triggers an exception. However, you may use other transition styles (except the partial curl transition) if the parent view controller is not in a popover.

Available in iOS 8.0 and later.

So:

self.definesPresentationContext = true
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:pillv animated:NO completion:nil];