Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISearchBar in UITableViewHeader strange animation on iOS 7/8

We have a class SearchTableViewController that holds a UISearchBar as the tableViewHeader of its UITableView. We also use a UISearchDisplayController whose delegate (searchResultsDelegate and searchResultsDataSource) is the same controller that holds the tableView containing the searchBar.

Searching itself works just fine, but the animation when entering/exiting search mode is really weird:

Weird animation 1

In another view controller (a subclass of the SearchTableViewController), the issue is even more noticeable:

Weird animation 2

I have tried implementing the various UISearchDisplayDelegate methods (such as -(void)searchDisplayControllerWillBeginSearch:), but they are either being called too late (when the animation is already finished) or only when giving the UISearchBars textfield the focus. Are there any methods I am missing that might allow me to change the animation before it happens? Also, notice how the navigation bar immediately disappears in the first video. I have tried manually setting it to 'not hidden' in multiple spots, which didn't change anything.

Our navigationBar is configured to not be translucent, if that makes any difference. On iOS 6, everything works as expected, the searchBar smoothly pushes the navigationBar upwards.

Will post code if necessary, but we are not modifying the standard behaviour in any way (setting frames, overwriting delegate methods etc.).

Any ideas what might be the cause for the strange animations?

like image 495
David Ganster Avatar asked Dec 13 '13 11:12

David Ganster


2 Answers

I talked with an Apple engineer at the iOS 7 Tech Talks, who also couldn't help me. After further investigation, I found the first problem to be the default behaviour for iOS 7(.0.4).

Update: The bug is still present in 7.1.

Second Update: The bug is still present in 8.1.

Third Update: The bug is still present in 8.4.

Fourth Update: The bug is still present in 9.2

Steps to reproduce:

  1. Create a new universal Master-Detail sample application in Xcode 5/iOS 7 SDK.
  2. Add a UISearchBar (EDIT: for iOS 8, use a "Search Bar and Search Display Controller") to the MasterViewController's TableView (doesn't matter if in InterfaceBuilder or in code)
  3. Run the project, enable slow animations and click on the search bar.
  4. The animations when starting/cancelling search are weird on the iPad, but look fine on the iPhone : Template project run on the iPad. I filed a bugreport about it, will update if this issue gets fixed.

About the second strange animation: The problem was that the first view controller was created from a nib while the second one was created programmatically. Therefore, the following calls were missing:

[self setAutomaticallyAdjustsScrollViewInsets:YES];
[self setExtendedLayoutIncludesOpaqueBars:YES];

After including these two lines in viewDidLoad:, the animation looks 'fine' - that is, same as buggy as the one from the sample project.

like image 147
David Ganster Avatar answered Nov 09 '22 02:11

David Ganster


My answer here helped my specific situation for strange animation behavior:

I found that

self.navigationController.navigationBar.translucent = YES;

made my animation less buggy

like image 23
Adam Johns Avatar answered Nov 09 '22 02:11

Adam Johns