How to push view controller with transparency mode?
Asked Answered
P

2

7

I am trying to push a view controller with transparency mode.

This is my code:

SearchViewController * searchViewController= [self.storyboard instantiateViewControllerWithIdentifier:@"SearchViewController"];
searchViewController.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7f];
[self.navigationController pushViewController:searchViewController animated:YES];

Something i did mistake find out and help me to solve this problem.

Parette answered 31/1, 2017 at 8:4 Comment(11)
You have to use custom transitionsAchitophel
Can you explain it how ??Parette
you want the transparent background or transparencey modeBlazer
@KishoreKumar could you provide any images that describe your issue?Achitophel
@WetSweater previous view controller have images so when i push a new view controller i need to show the things with blur transparency effectParette
@Blazer bro transparency mode neededParette
use `searchViewController.modalPresentationStyle = UIModalPresentationCurrentContext;searchViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; // fadeBlazer
I think this is what you are looking for medium.com/@A2HGO/…Erythrite
@KishoreKumar do you solve this?Holozoic
@SergeyDi u have to play with alphaParette
@KishoreKumar I tried, but it shows black screen.Holozoic
S
-2

You have to set modalPresentationStyle with overFullScreen value

let viewController = SearchViewController(nibName: "SearchViewController", bundle: nil)
viewController.modalPresentationStyle = .overFullScreen
present(viewController, animated: false, completion: nil)
Stramonium answered 2/1, 2020 at 17:56 Comment(0)
F
-3

In iOS the default color of background is black. So you navigation controller has a black background.

If you push a controller, you current controller will be replaced by your new one. If the new one have a transparent color you will see the view of your navigation.

If I understand you want your first controller to be still visible ? If yes, then you should use :

SearchViewController * searchViewController= [self.storyboard instantiateViewControllerWithIdentifier:@"SearchViewController"];
searchViewController.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7f];
[self presentViewController:searchViewController animated:YES completion:nil];

You can also use a custom segue to have the cor

Forwent answered 31/1, 2017 at 8:14 Comment(2)
Yes I tried this before working ,but my case is from push ->view controller is it possible ?Parette
It depend: Do you want still see you first controller ? If yes you have to use presentViewController or something like steveen zoleko suggest : medium.com/@A2HGO/…Forwent

© 2022 - 2024 — McMap. All rights reserved.