I am trying to create a similar experience for contact apps in iOS 8. The main components of this are:
- Hold the search bar below the navigation bar
- When the search bar is displayed at the top of the view (standard functionality).
This, however, is easier said than done. Some time later, using tableHeaderView (which did not allow interaction before table presentation and was difficult to position viewDidLayoutSubviews ), I decided to include a UITableView within the UIViewController , so I could add a UISearchBar as a subtitle. This worked pretty well and allowed it to interact with the search bar in all scroll positions, and the inserts were not difficult to count.
But the search bar turns off below the status bar when it is activated. It seems like a direct problem - even if I did not try it with the same implementation in the UITableViewController , So I tried to make sure that all my properties are set up for alignment, in every possible controller.
self.edgesForExtendedLayout = UIRectEdgeNone; self.extendedLayoutIncludesOpaqueBars = YES; self.automaticallyAdjustsScrollViewInsets = NO;
I tried every possible combination of them: viewWillAppear, as well as viewDidLoad, as well as translucent navigation bars and different start frames for the table and the search bar. Bad luck. So, I tried to adjust the framework or restrictions, perhaps using topLayoutGuide or just 0. Unfortunately, adjusting the frame in any of the UISearchControllerDelegate methods did not actually change its position, and adding restrictions immediately worked when the active animation started (due to that super.top did not exist in the presentation hierarchy at that time, removing constraints in willPresent did nothing).
After the battle is still a bit, I tried to implement positionForBar as a delegate of UISearchBar :
- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar { return UIBarPositionTopAttached; }
She seemed to adjust the height, but the search bar goes to the top of the view. When activated, the search bar appears directly above the visible area. This is even worse than clipping behind or below the UIStatusBar . I also tried just to hide the status bar when the search controller becomes active, but the conditional implementation of prefersStatusBarHidden does not work at all (returning YES works fine without the UISearchController ), but when it is active, it shows the status bar again or it appears below it). I assume this is because the UISearchController refuses to obey any standards or rules, as it is now painfully clear.



I have been trying to figure this out for a few days, and I cannot come up with a solution other than completely redefining the UISearchController class / animation. Please, help!