2

I have a custom view header on a Table View Controller, and within that I have a couple labels and a UISearchBar. This issue is when I cancel out of the Search Display Controller, the UISearchBar animates back into it's origin, but upon finish it changes its height to the custom view's height like so:

Original Before Search SearchBar Height Overlapping after cancelling

Is there a way to prevent this from happening without AutoLayout (project is using struts and springs)? Or is there a method to override the animation coming out of the Display Controller?

I've uploaded a quick sample project to github: https://github.com/3arrett/searchbarheight

barrett
  • 327
  • 1
  • 9

1 Answers1

1

UISearchBar will be placed in the center of the top container view after animation, so the solution I have got is to place two UIView, one for UISearchBar, another for Labels, also the height of the UIView which contained the UISearchBar should be same height as UISearchBar, for instance, 44.

Looks like this one - enter image description here

Tom
  • 4,612
  • 4
  • 32
  • 43
  • My understanding is that is adding a searchBar to the `tableHeader` and the view/labels to the `tableFooter`, with the desired outcome to have everything above the `tableView`. I've updated the project on git to try this but it's still not working. – barrett Jan 03 '14 at 06:33
  • Not that. In the original project you did, you added search bar and labels in one view, but now you can add two views, one for search bar, one for labels, and the one which contains search bar, the height is 44 that's all. – Tom Jan 03 '14 at 18:58
  • Similar to @zeanstoi's answer where having a view that just contains the searchBar. The issue that I see, visually, is the animation completes to where I expect it to go, but then upon completion the `searchBar`'s frame gets set to the `tableHeader` view, not the immediate `superview` of the `searchBar`. – barrett Jan 03 '14 at 19:09
  • I've updated it now. When looking at storyboard, the two `UIView`s above and below the `TableViewCell` can't be positioned at all, and it won't allow you to add any more sibling views. If you run it, then enter search, then cancel you'll see the animation I'm talking about. – barrett Jan 03 '14 at 19:18
  • Yeah, you are right. I didn't figure out a good way to do so. I tried to move labels to section header, and check this https://github.com/hellomaya/searchbarheight, but I am afraid that is not what you want exactly. – Tom Jan 03 '14 at 20:37
  • Another way, just an option, try use UIViewController and add an UITableView in it, by implement UITableViewDelegate and UITableViewDataSource, will be easier to control Search bar position. – Tom Jan 03 '14 at 20:39
  • Yeah, I wanted to avoid utilizing section headers because the implementation I'm using could potentially use grouped tableViews. And I'm thinking right now the best solution is to not use the Search Display Controller and just using the search bar and hooking it into reloading the current `tableView`, unideal but it seems that Apple's default implementation isn't taking custom height headers into account. – barrett Jan 04 '14 at 19:36
  • Yeah always wondering there gonna be a way, just didn't find it yet. Hope you make it your own solution. – Tom Jan 04 '14 at 21:17