PresentViewController black background instead of transparent

I have an idea of ​​what I want to present to the user in a standard way (sliding up from the bottom of the screen). About half of this view is a transparent background, and the bottom half has several input fields (imagine how the keyboard opens). When I call [self presentViewController] in rootViewController, it shifts the view up, but then after about half a second, when the image was transparent, it is replaced with black instead. This happens with both presentViewController and presentModalViewController. How to change this behavior?

+8
ios ios5 ios6
source share
5 answers

In the end, it doesn't seem like it can be transparent, I circumvented this by adding this view as a subordinate outside the boundaries of the root view controller, and then shifted it into place using an animation block. Not a lot of extra code, but it would be nice to be able to use the standard iOS behavior for this.

-one
source share

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

iOS 8 UIModalPresentationCurrentContext not transparent?

This is a solution referencing a balboa request in Objective-C:

Before iOS 8, you do the following:

 [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 complement the above code with the Swift equivalent:

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

Implementing this with Xcode 6.3 beta 3 on iOS 8.1 with Swift 1.2, it works great.

Just a comment in which I looked at three different SO questions - these are later, now marked as duplicates - before searching and trying to solve the Ray Wenderlich forum.

+21
source share

As far as I know, transparent background is not supported when you present a model view controller. Try storing the controller in the root view controller and just add subview to the root view controller.

+3
source share

Using SWIFT 4, just add this code to the view controller, which should have a transparent background.

 override func viewDidLoad() { super.viewDidLoad() self.modalPresentationStyle = .overFullScreen self.view.backgroundColor = UIColor.clear } 
+1
source share

I had a similar problem with a black background appearing after a slight delay when creating the controller using

  Disclaimer *vc = [[Disclaimer alloc]init]; 

For me, the problem of creating the corresponding object in IB and creating an instance of the viewcontroller using the storyboard identifier was solved:

  Disclaimer *vc = (Disclaimer *)[self.storyboard instantiateViewControllerWithIdentifier:@"SBIDDisclaimer"]; [self presentViewController:vc animated:YES completion:nil]; 

I assume that through IB some additional initializations.

0
source share

All Articles