two little questions regarding the UISearchBar/SearchDisplayController:
Is it possible to prevent/hide the overlay which appears when a searchbar is clicked?
If the Searchbar is entered, the Tabbar and the NavigationBar of the current Screen disappears (and dont reappear after leaving the SearchBar) - how can i prevent that?
Is it possible to prevent/hide the overlay which appears when a
searchbar is clicked?
Why don't you just use a UISearchBar with the current table and not a UISearchDisplayController? One of the main features of the UISearchDisplayController is it's modal type display. With only the UISearchBar, you can search the current view.
Related
I have a view controller with a UISearchController that, when tapped, will expand and bring up the keyboard. I want the user to press a button (separate from the search controller), when then brings up the search bar without actually tapping it. Is this possible?
What you want to achieve is to make the searchBar become the first responder. You can do that with:
searchController.searchBar.becomeFirstResponder()
I've tried to use all the properties UISearchBar has with different combinations, I've searched for the answer for a while but still can't solve the problem.
Problem:
I have a UIViewController with UITableView in it and some other view in storyboard. I've added Search Bar and Screen Display Controller into my project (search bar is added as a subview/header of the UITableView)
I need to make it red color with no transparency/translucency to match my navigation bar.
I've tried "solution" from How to change background color of UISearchBar in iOS7 but it doesn't work. Result of this solution looks like that:
searchDisplayController?.searchBar.barTintColor = UIColor.myAppRedColor()
searchDisplayController?.searchBar.translucent = false
As you can see - that isn't exactly matching Navigation Bar color. It also has a separator between navbar and search bar.
Next solution almost worked:
searchDisplayController?.searchBar.backgroundImage = UIImage()
searchDisplayController?.searchBar.backgroundColor = UIColor.myAppRedColor()
But when I tap on the search bar it changes color:
It also has very weird animation:
https://youtu.be/Dq1GKBGbmTc
Do you have an idea what else I can do instead of implementing my own SearchBar?
Do not use Search Display Controller. Instead use only searchBar and TableView.
Simply delete Search Display Controller from your storyboard.
You will receive delegate methods of searchBar.
Here you can apply search on tableView.
Update 03/25/14
It looks like the lack of animation was a bug in iOS 7.0, and has been fixed in iOS 7.1.
Original Question
Normally, when you tap inside a search bar in iOS 7, it has a nice little animation where the magnifying glass and "Search" text slides from the middle of the search bar to the left side. However, if I put the search bar in the navigation bar instead of within a table view, it no longer animates. Instead, the magnifying glass and "Search" text jumps instantly to the left side of the search bar.
You can see this really easily using Apple's UISearchBar sample project. Open up the storyboard. Add a boolean runtime attribute displaysSearchBarInNavigationBar on Search Display Controller, and check the checkbox it creates. Then, move the Search Bar up a level in the tree, so it is outside of the Table View. Run the project, and the search bar should now be in the navigation bar. Note that when you tap in the search bar, it doesn't animate.
Has anyone successfully put a UISearchBar in the navigation bar in iOS 7, and had it animate properly?
To be clear, my problem is that there is no animation of the search bar between the first and second screenshots below, when the user taps on the search bar.
In iOS 7, the UISearchDisplayController supports this by default. Set the UISearchDisplayController's displaysSearchBarInNavigationBar = YES for to get this working easily.
Apple Inc Doc:
Starting in iOS 7.0, you can use a search display controller with a
navigation bar (an instance of the UINavigationBar class) by
configuring the search display controller’s
displaysSearchBarInNavigationBar and navigationItem properties.
your expected answer
Remove the search bar from the table view. Using displaysSearchBarInNavigationBar means that UISearchDisplayController will take care of placing the search bar in the hierarchy for you.
- (void)viewDidLoad
{
self.searchDisplayController.displaysSearchBarInNavigationBar=YES;
}
This was not animation first time tap but the animation works good in cancel moments:
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:YES animated:YES];
}
-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:NO animated:YES];
}
Hey I have been trying to customize a UISearch bar with display controller and have run into some issues customizing certain aspects of the search and display controllers. I'm using storyboard and am developing with the most recent version of IOS 6.
The first issue is eliminating the dark grey gradient overlay that appears when you first click on the search text view. I have tried to use the searchDisplayController:willShowSearchResultsTableView: delegate but am unable to either find the view that is being used as the gradient overlay or a property to disable it. How do I remove this view?
The second is I am having an issue with the initial animation that is triggered when the search view is clicked. The animation is supposed to expand the search bar over the UINavigationBar to allow for a larger space to view the results. This doesn't happen and the search bar stays below the UINavigationBar and the animation doesn't properly show. I have tried setting the displaysSearchBarInNavigationBar and navigationItem properties but couldn't find any way to access or set them. Could this be an issue with the fact that I'm using autolayout in my story board? I have noticed that many issues relating to the UISearchBar animations are due to autolayout being used in the .xib or storyboard file. How can I make it correctly over the navigation bar?
The third issue I am having is with over ridding the searchBarTextDidBeginEditing:(UISearchBar *)searchBar delegate method. I have subclassed the UISearchBar to allow for complete customization. Is there a way to provide a default definition for the searchBarTextDidBeginEditing: delegate method inside my custom UISearchBar subclass. I want to provide a specific style of text in the UITextView when the user clicks on the search bar and don't want to have to redefine this method in every view controller that uses the search bar. Is this possible?
Thanks for the help in solving these issues.
I read several answers to this question but couldn't figure out how to do it. I'm using Xcode 4.2 with ARC and no storyboards.
I'm developing an app based on the TabBar application template and extended it to contain 4 UITabBars. I'm not using UINavigationController but instead using UINavigationBar next to the status bar. When the app is loaded with the first tab shown, I have a button on the UINavigationBar and when I press it, I want to hide the UITabBar and instead show the UIToolBar at the same location where the UITabBar was located.
I tried to hide and show using the hidden property (hiding the UITabBar and showing UIToolBar). What happens is the UITabBar is hidden but the UIToolBar is shown above the location where the UITabBar was shown before. This looks ugly and I want it to be shown at the very bottom of the screen.
I think I can't use hidesBottomBarWhenPushed as I don't use a UINavigationController but instead using Navigation bar directly.
Also, I want to revert back to showing the UITabBar and hide the UIToolBar when pressing the same button on the UINavigationBar.
I am not sure if my idea would work for your scenario. Here it is...
but before, just let me tell you that hiding UITabBar, unlike hiding UINavigationBar is not animated. So to me, hiding tabBar is not a user-friendly approach, unless you create your own subclass of UITabBarController that animates hiding the UITabBar.
You can use presentModalViewController:animated and dismissModalViewControllerAnimated: methods. The viewController that is being shown modally can have a UINavigationBar, it pops out from the bottom of the screen and covers the UITabBar with animation.
Hope that helps.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html