user1272965
user1272965

Reputation: 3064

Transparent vc over TabBarVC in iOS > 8

There are many q/a's on this topic, many of them referring to older versions of iOS. The best answer I could find on the subject was this one.

It almost works for me, but when presenting this over a UITabBarViewController subclass, it only partially works: I get a nice, semi-transparent view during the presentation animation, but once the presentation animation completes, the presented VC becomes opaque again.

Coded in Objective-C, but I'm happy to read Swift answers...

- (void)showBusyWithCompletion:(void (^)(BOOL))completion {
    UIViewController *vc = [[UIViewController alloc] init];

    vc.view.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.5];
    vc.view.opaque = NO;

    vc.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentViewController:vc animated:YES completion:^{
        [self performSelector:@selector(hideBusy:) withObject:vc afterDelay:4];
    }];
}

- (void)hideBusy:(UIViewController *)vc {
    [self dismissViewControllerAnimated:vc completion:nil];
}

Again, the presenting VC is a UITabBarVC subclass, with nothing done to it except some code to record which tabs were visited. The presented vc is a vanilla view controller. Its view appears transparent red as it slides over, then turns opaque red (darker, like it's being blended with black) once the transition is complete.

How can I keep the background transparent after it appears?

Upvotes: 1

Views: 31

Answers (1)

user1272965
user1272965

Reputation: 3064

It turns out that the answer I refer to above is correct, and I transcribed the setting improperly. To recap: this doesn't work (and the other answer didn't claim it did):

vc.modalPresentationStyle = UIModalPresentationCurrentContext;

...but either of these do:

vc.modalPresentationStyle = UIModalPresentationOverFullScreen;

or as @TylerTheCompiler points out:

vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;

Upvotes: 1

Related Questions