UIVisualEffectView setHidden=YES extremely slow - weird bug?

Testing in iOS 8.0 currently.

I am facing a weird bug (possibly) with UIVisualEffectView.

I add the view on top of the entire view controller's view as such:

-(void)showBlur{
    if (!self.blurview) {
        self.blurview = [[UIView alloc] initWithFrame:self.view.frame];
        UIVisualEffect *blurEffect2;
        blurEffect2 = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
        UIVisualEffectView * visualEffectView2 = [[UIVisualEffectView alloc] initWithEffect:blurEffect2];
        visualEffectView2.frame = self.view.frame;
        [self.blurview addSubview:visualEffectView2];
        [self.view addSubview:self.blurview];
    } else {
        self.blurview.hidden=NO;
    }
}

Above is all fine and I see a blurred view on top of the entire view. However when I need to hide the entire blur view as such:

-(void)hideBlur{
    NSLog(@"This gets printed before hidden: %@",[NSDate date]);
    self.blurview.hidden=YES;
    NSLog(@"This gets printed after hidden: %@",[NSDate date]);
}

Some how all 3 lines of code get executed but my blur view is still visible. If I wait for around 5-10 seconds, then the blur view disappears. Also note that even though the blur view is "visible" (though it should be hidden now), I am somehow still able to interact with the views which are under the blur view. I see their blurred outlines move and stuff when I interact with them. But the blur view takes 5-10 seconds to disappear.

I tested with NSLog statements and break points and see that the ".hidden" does get called successfully in time but the view stays visible for 5-10 seconds.

Above prints out:

2015-09-09 00:55:21.542 Kitty[8600:1094199] This gets printed before hidden: 2015-09-09 04:55:21 +0000
2015-09-09 00:55:21.543 Kitty[8600:1094199] This gets printed after hidden: 2015-09-09 04:55:21 +0000

Is this some sort of bug??

Edit 2: I had initially tested with the visual effect view being the view itself instead of adding it as a subview of another UIView. Same issue there too.

Upvotes: 2

Views: 781

Answers (1)

I was able to resolve this myself. I was initially calling the hideBlur method from another dispatch_async queue other than the main queue. I resolved it by putting the UI update portion on the main queue like this:

-(void)hideBlur{
    NSLog(@"This gets printed before hidden: %@",[NSDate date]);
    dispatch_async(dispatch_get_main_queue(),^{
        self.blurview.hidden=YES;
    });
    NSLog(@"This gets printed after hidden: %@",[NSDate date]);
}

Upvotes: 2

Related Questions