I've seen a bunch of examples on SO that do the same thing in a custom UIStoryBoardSegue
's perform
method to implement a modal with a transparent background, but when I try doing this, as soon as the animation finishes and presentViewController is called, the modal's black background instantly comes right back. Here's the code:
- (void)perform {
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;
sourceViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[sourceViewController.view addSubview:destinationViewController.view];
destinationViewController.view.alpha = 0;
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
destinationViewController.view.alpha = 1;
} completion:^(BOOL finished) {
[destinationViewController.view removeFromSuperview];
// boom, the black background returns!
[sourceViewController presentViewController:destinationViewController animated:NO completion:^{
// these have no effect
destinationViewController.view.backgroundColor = [UIColor clearColor];
destinationViewController.view.superview.backgroundColor = [UIColor clearColor];
}];
}];
}
I'm also setting the modal presentationStyle to "Current Context" in the source VC through IB:
I'm not using a UINavigationController
.
As you can see I've tried setting the background color of the destination view controller, the superview of the destination view controller, setting .modalPresentationStyle
on the sourceViewController and destinationViewController, but nothing seems to work!
If I comment out the part that removes the destination view from its superview, and the presentViewController:
call, everything works fine, but then destination VC is dealloc'ed so I'm unable to interact with it and/or unwind it later. Really at a loss here.
Edit: Another issue I'm seeing in the console after going this route is an Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x7f86a042c114>.
error.