Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

presentViewController black background instead of transparent

Tags:

ios

ios6

ios5

I have a view that I wish to present to the user in the standard way (sliding up from the bottom of the screen). About half this view is a transparent background and the bottom half has some input fields (imagine the way the keyboard pops up). When I call [self presentViewController] on the rootViewController, it slides the view up, but then about half a second later, where the view used to be transparent it is replaced with black instead. This happens with both presentViewController and presentModalViewController. How to change this behaviour?

like image 418
Jacob Joz Avatar asked Oct 29 '12 05:10

Jacob Joz


1 Answers

This is possible, and rockybalboa provides a solution to this issue in the forum post on raywenderlich.com:

iOS 8 UIModalPresentationCurrentContext is not transparent?

That solution being, quoting balboa's answer, in Objective-C:

Before iOS 8, you do this:

[backgroundViewController setModalPresentationStyle:UIModalPresentationCurrentContext];
[backgroundViewController presentViewController:_myMoreAppsViewController animated:NO completion:nil];

in iOS 8, you have to do this:

backgroundViewController.providesPresentationContextTransitionStyle = YES;
backgroundController.definesPresentationContext = YES;
[overlayViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext];

To supplement the above code with the Swift equivalent:

backgroundViewController.providesPresentationContextTransitionStyle = true
backgroundController.definesPresentationContext = true
overlayViewController.modalPresentationStyle = .OverCurrentContext

Having implemented this using Xcode 6.3 beta 3 on iOS 8.1 with Swift 1.2, it works perfectly.

Just a comment that I viewed three different SO questions on this - the more recent now marked as duplicates - prior to finding and attempting the Ray Wenderlich forum solution.

like image 164
Max MacLeod Avatar answered Oct 25 '22 00:10

Max MacLeod