Reputation: 2242
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 :
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.
Upvotes: 0
Views: 60
Reputation: 1933
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];
Upvotes: 0
Reputation: 3981
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?
Upvotes: 0