简体   繁体   中英

Show transparent background for modal view

I want to show a modal view via my navigation controller, and background of this view should be transparent. In the modal view controller I clear background on viewDidLoad as follow:

self.view.backgroundColor = [UIColor clearColor];

I show this view as follow:

ModalViewController *modalViewController = [[ModalViewController alloc] init];
[self.navigationController presentViewController:modalViewController animated:YES completion:nil];

As result my view is shown, but background is black. I've tried to do:

[self setModalPresentationStyle:UIModalPresentationCurrentContext];

For all my view controllers, include NavigationController. I've tried to do:

self.navigationController.providesPresentationContextTransitionStyle = YES;
self.navigationController.definesPresentationContext = YES;

However all of this doesn't work. Is it possible to implement my task, or I should show my view using another way?

Have you checked out this question on SO Display clearColor UIViewController over UIViewController ?

It seems to have the answer to your question. Basically you have to set presentation style to 'UIModalPresentationCurrentContext'.

I used UIModalPresentationCurrentContext instead of the UIModalPresentationOverCurrentContext. Using the UIModalPresentationOverCurrentContext fixed this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM