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.

Kishore Kumar
  • 4,265
  • 3
  • 26
  • 47

2 Answers2

-2

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

djidji
  • 17
  • 3
  • 1
    Yes I tried this before working ,but my case is from push ->view controller is it possible ? – Kishore Kumar Jan 31 '17 at 08:16
  • It depend: Do you want still see you first controller ? If yes you have to use presentViewController or something like steveen zoleko suggest : https://medium.com/@A2HGO/blurred-translucent-ios-navigation-controller-transitions-f38934204f46#.fwggl81td – djidji Feb 03 '17 at 21:42
-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)
Igor
  • 4,235
  • 3
  • 34
  • 32