Search bar getting hidden by navigation bar when becomes active - ios

I am facing a weird scenario, I have used a search bar in my application and tied it up with a table view as is seen in the below image!
But when ever I try to search anything the search bar slides up and gets hidden by navigation bar, I have used search bar a number of times and never seen me thing like this below is its screen shot !
I can't remove the navigation bar since I need it, but I just can't figure out why or how it can be happening,
One point to note is that the search bar and it's controller are working perfectly when tried to search, only thing is it's getting hidden behind the navigation bar,
Any help on this would be appreciated, as I just can't figure out its reason.

Try this:
Set the navigation bar's translucent property to NO:
self.navigationController.navigationBar.translucent = NO;
This line will fix the view from being framed underneath the navigation bar and status bar.
If you have to show and hide the navigation bar, then use this code in viewDidLoad
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone; // iOS 7 specific

Related

Can see Status Bar space but not information in iOS Swift

I add Navigation Controller(2nd View) and add one UIViewController(3rd View) as root view controller.
And then I connect segue to Navigation Controller(2nd View) from anther UIViewController(1st View).
So I can see navigation Bar with Status bar space when the view is presented.
But the information like Carriers, batteries, time information are not shown in Status Bar.
(I changed navigation Color to pink for showing you the problem.
The blue part is title view for navigation bar.)
So I tried 2 solutions.
First, I thought StatusBar Color problem. But it was not.
UIApplication.shared.statusBarStyle = .default
Second, I tried following code for showing. It was not also.
override var prefersStatusBarHidden: Bool {
return false
}
and
UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.none)
I need to solve this not-showing problem with status Bar.
I can see status Bar space but not information.
There are lots of ways to toggle the color and visibility of the status bar in iOS.
Similar question with possible correct answers for you:
How to change Status Bar text color in iOS 7
In short, if you want to toggle it between every screens, follow these steps:
In your info.plist, add this new key:
View controller-based status bar appearance and value should be NO.
In your viewWillAppear, toggle the status bar with the code you have posted:
UIApplication.shared.statusBarStyle = .lightContent - white
or
UIApplication.shared.statusBarStyle = .default - black
Edit:
Initial ViewController --> Present Modally --> NavigationController + ViewController.
This is how you set up your screens, right?. If so,
You can setup the status bar in your NavigationController properties in your Interface Builder.
And toggle the visibility and/or color of your status bar in side the viewWillAppear of your 3rd ViewController.
I suggest you check out Debug View Hierarchy.
Based on my experiences in previous projects, if I can't come up with code-based solutions on UI-related problems the simplest debugging technique that I can do is check the view hierarchy during run time.
See if the Navigation Controller View blocks the Main View which can possibly hide the status bar and if yes, work your way on solving it.
I hope it helps.

IOS Search bar that appears below navigation

I am attempting to have a search bar tied to my UISearchController that appears below the navigation bar, similar to this:
Currently the search bar replaces the title as is common in most/all IOS apps I've seen. I've attempted to control the search bar presentation through a few methods:
1) Creating a new view that sits underneath the nav bar, and assigning the SearchController's search bar to it.
//instead of:
//navigationItem.titleView = searchBar
//do this:
searchplaceholder.addSubview(searchBar)
However the search bar shows up 1/2 way down the screen.
2)Second attempt was to move the frame of the search bar to origin:
searchBar.frame = CGRectMake(0, 0, self.view.frame.width, searchBar.frame.height)
view.addSubview(searchBar)
resultSearchController?.active = true
Looks good initially:
But as soon as I start typing, the bar jumps low again:
How can i Hijack the SearchController to present it's bar either in the nav bar without hiding the page title or constrain the search bar to appear right under the nav bar?
The long and short of this is that you can not do what I was attempting to do. You create a searchbar that when clicked transitions to a second screen with a searchbar in the header. This provides the cleanest experience compared to what I have listed above.

How to apply styles on Google Places Autocomplete UI (full-screen) control on iOS

I've added the Google Places Autocomplete UI control in full-screen mode in my iOS application. Is there any way i can change the navigation bar's background color/tint color in this control?
I have also tried adding a new view controller in my application in an attempt to have better control on the styling. In this new view controller I have my navigation bar with the styles i want, and then added a UISearchController positioned at the top of the view (below the navigation bar). I linked this search controller with a results controller as described in the API docs here:
https://developers.google.com/places/ios-api/autocomplete#add_a_results_controller
However, as soon as i start typing something in the search bar, the results view hides the navigation bar.
I've also added the below code (again as described in the API docs), but it doesn't help either:
self.navigationController.navigationBar.translucent = NO;
_searchController.hidesNavigationBarDuringPresentation = NO;
// This makes the view area include the nav bar even though it is opaque.
// Adjust the view placement down.
self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeTop;
Any help will be greatly appreciated!
UPDATE: I think the Autocomplete control only works properly when used in a navigation controller based app. I didn't have one. Now that I've added the navigation controller, the global styles for navigation bar and status bar which i had already defined in app delegate seem to affect the autocomplete modal as expected. The other issue where the navigation bar would get hidden completely as soon as i typed anything in the search box seems to have been fixed as well with the inclusion of navigation controller.
With the latest release of the Autocomplete control (1.11.1, run pod update in your project to make sure you have the latest version) you can tint the navigation bar in a GMSAutocompleteViewController using the appearance proxy, for example:
[[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];
This should work whether or not you're using navigation controllers elsewhere in your app.

Search Bar in Navigation Bar in iOS 7

I'm relatively new to iOS programming and I have a Table View Controller that has a Navigation bar at the top and i'm trying to get the search bar from "search bar and search display controller" to appear in the navigation bar.
I've googled around and i've found that:
self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
is supposed to solve my problem but i'm not sure exactly where I would put it. Does it go in the table view controller or do I have to make another control? I've tried creating a UISearchDisplayController class but I couldn't find a way to link it to the search bar. Any help?
You can put this in the viewDidLoad of your view controller. If you are using story boards you create a UISearchDisplayController and Search bar and drag it into your table header.
Keep in mind that if you use the navigation bar for your search bar, it will not show the scope bar.

UINavigationBar disappears before pushing view animation and appears after it. Whats wrong?

I have three views and a navigation bar with my background image. When I push second view, everything goes like it should: navigation bar stays on its place with background image, just caption and buttons swipe away to the left and get replaced by "back" button and new caption for the second view. But when i push a third view, the transition goes like this: just right before animation, navigation bar disappears totally, leaving app's window background color on its place, and then, new navigation bar swipes from the right with all the ui element. and the same goes when i pop third view (push "back button").
Any ideas, why it is happening? It was normal before, but at the some point I noticed it start working like this.
Just out of curiosity, do you have a UISearchBar in the view you are pushing onto the stack? I was having the exact same issue as you described, it turned out it was caused by the UISearchBar and UISearchDisplayController.
When creating the UISearchBar and UISearchDisplayController I was calling
self.searchBar = [[[UISearchBar alloc] init] autorelease];//init the UISearchBarView
then somewhere further along in the code I was calling
[self.searchDisplayController setActive:YES animated:NO];
[self.searchDisplayController setActive:NO animated:NO];
The above two calls to "[setActive: animated:]" would layout the UISearchBar correctly for some unknown reason. I have seen this solution in many places on the interwebs. But a side effect would be that the navbar turns white when pushing a new view that had a search bar.
To fix everything I instead initialized the UISearchBar by calling:
self.searchBar = [[[UISearchBar alloc] initWithFrame:frame] autorelease];
and then I deleted the two calls to "[setActive: animated:]"
This change resulted in a properly laid out search bar without the disappearing navbar.
Hope somebody will find this post useful!
You aren't pushing a UINavigationController on top of your main navigationController?

Resources