0

I've built an UIView in storyboard that is composed like this:

UIView (called _view)

 UIVisualEffetView (dark)

  UIVIew

   Button

I've done like this for the ability to reuse it between several Navigation Controller. So for this I've set everything and I can show my view in my main controller called "ViewController" that is embedded in a navigation controller. But the issue is that the blur is opaque, for example the blue navigation bar of my view controller is not visible under the UIVIsualAffectView !

Here is the code I use for setting up the custom view :

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup {
    _view.backgroundColor = [UIColor clearColor];
    UIView *rootView = [[[NSBundle mainBundle] loadNibNamed:@"SideMenuView" owner:self options:nil] objectAtIndex:0];

    CGRect newFrame = rootView.frame;

    newFrame.size.width = [[UIScreen mainScreen] bounds].size.width / 2;
    newFrame.size.height = [[UIScreen mainScreen] bounds].size.height;
    [rootView setFrame:newFrame];

    UIWindow* currentWindow = [UIApplication sharedApplication].keyWindow;
    currentWindow.backgroundColor = [UIColor clearColor];
    currentWindow.windowLevel = UIWindowLevelNormal;

    [currentWindow addSubview:rootView];

}

And here is the code I use to call the view from my main controller:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self.leftBarButton setTarget:self];
    [self.leftBarButton setAction: @selector(test)];
}

- (void)test {

    SideMenuView *test = [[SideMenuView alloc] init];
    [self.view addSubview:test];
    test.translatesAutoresizingMaskIntoConstraints = NO;

}

I've also tried to force the property "setOpaque" to No in my SideMenuView.m but without effect

Here is a screenshot of what it do:

enter image description here

Do you know guys what is wrong with my code ?

I've also added a button in the middle of the screen with a blue background but it's not visible under the blur so the issue is not navigation bar specific

Thanks in advance for your help !

Synny
  • 542
  • 1
  • 4
  • 18

1 Answers1

0

I've resolved my issue by simply creating an UIView with clear background. What I do for adding the blur effect is to create the UIVisualEffectView programmatically (doing this way it work perfectly !). After that I'm adding my UIView as a subview of my UIVisualEffectView and voila :)

Synny
  • 542
  • 1
  • 4
  • 18