0

need help in adding search bar ViewController which whose SearchBar will be in NaviagationBar with Back button (navigation search i achieved - self.navigationItem.titleView = searchBarView) throughout app, but until it has search i want to show previous ViewController in background with semi-transparent black color just like i achieved in Android :

enter image description here

i can add semi-transparent ViewController to current ViewController :

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
[vc setTransitioningDelegate:transitionController];
vc.modalPresentationStyle= UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:nil];

but what it is doing that it opens SecondViewController in transparent without NavigationBar, the FirstViewController has NavigationBar

And when the SecondViewController is opened it should have SearchBar in NavigationBar and it shouldn't be Transparent as i achieved in Android. There will be n number of ViewController which will add this same controller as Overlay Controller with NavigationBar and back button. Please Help.

SML
  • 2,172
  • 4
  • 30
  • 46
  • did u look into addng blur view ? – Teja Nandamuri Jan 05 '16 at 16:27
  • no, semitransparent but with NavigationBar without transparent – SML Jan 05 '16 at 16:29
  • Is there a reason you don't add the navBar functionality to the viewController whose view you want to capture in the background? Otherwise, you could take an image snapshot of the last VC and use that as the background for your navBar controller. – Alex Jan 05 '16 at 16:50
  • @Alex is there any solution take a screenshot without NavigationBar of previous ViewController – SML Jan 05 '16 at 17:02
  • Yeah, I've never done it but here is a possible solution. In the solutions I've seen you will eventually use some CGGraphics: http://stackoverflow.com/questions/10365735/ios-iphone-is-it-possible-to-clone-uiview-and-have-it-draw-itself-to-two-uiviews – Alex Jan 05 '16 at 17:06

2 Answers2

0

I found some solutions which involve taking a snapshot of the view and adding them to your navBar controller.

From Apple: https://developer.apple.com/library/ios/qa/qa1817/_index.html

Other interesting option: iOS iPhone is it possible to clone UIView and have it draw itself to two UIViews?

Community
  • 1
  • 1
Alex
  • 3,861
  • 5
  • 28
  • 44
  • thanks for reply, but this case will fail in Landscape mode. suppose First ViewController is in Portrait mode and if i take screenshot of portrait and set as background of searchcontroller then in Landscape mode the image which i passed in Portrait will not look same as Landscape it will be stretched. – SML Jan 06 '16 at 09:42
  • Can you apply a transform to the view to match the rotation? – Alex Jan 06 '16 at 13:08
0

In you code snippet you just create new SecondViewController and present it like modal. It appears without navigation bar because you create it without Navigation Controller. If you want to keep SecondViewController in the same navigation stack as previous ViewController with navigation bar and default Back button you should call:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self presentViewController:vc animated:YES completion:nil];
[self.navigationController pushViewController:vc animated:YES];

To make SecondViewController like semitransparent, take screenshot of previous view controller, pass this image to SecondViewController and use it like background. You can apply this image to additional ImageView on your SecondViewController view or just call:

self.view.backgroundColor = [UIColor colorWithPatternImage:self.backgroundImage];
shpasta
  • 1,913
  • 15
  • 21