iOS 7 UISearchDisplay controller is hiding Navigation controller's bar - ios

I have this problem on the app I am transitioning to iOS 7 from iOS 6.
I have a navigation bar in xib, under them is a tableview with attached UISearchDisplayController subclass; because I had to handle searching default behaviour which make the search bar go up and hides the navigation bar below it in iOS 6 by the following code:
-(void)setActive:(BOOL)visible animated:(BOOL)animated
{
if(self.active == visible)
{
return;
}
[self.searchContentsController.navigationController setNavigationBarHidden:YES animated:NO];
[super setActive:visible animated:animated];
[self.searchContentsController.navigationController setNavigationBarHidden:NO animated:NO];
if (visible) {
[self.searchBar becomeFirstResponder];
} else {
[self.searchBar resignFirstResponder];
}
}
Now that I want to transition it to iOS 7, the behaviour changed, whenever I write text inside search bar, navigation bar is hidden without the search bar going up, and search results table is overlapped by search bar, so the navigation bar stays hidden until search is ended.
I want to know what is the cause of this behaviour and how can I maintain the same behaviour without hiding the navigation bar.
Thanks in advance and all help is appreciated.

As far as the cause of the behavior, I believe this the standard operating procedure for UISearchDisplayControllers (as well as iOS 8's UISearchController). UINavigationControllers, UITableViews, etc. act in very special ways as far as appearance an animation when a UISearchBar is found as the tableHeaderView of a UITableView.

Related

iOS 10 Beta makes navigation bar buttons and title disappear on pushViewController

EDIT: Please watch the video of my issue here:
https://www.dropbox.com/sh/lzgs9mahx5mea13/AADLYfLQix7MDleDN1ER81qVa?dl=0
I have had an app live in app store which works perfectly fine on iOS 9.
However on iOS 10 (tested on device iPhone 6s with latest beta), when the cell on the master view controller is selected and the detail view is "pushed", my navigation bar's title and navigation bar buttons disappear.
Only the back button is visible.
Even if I pop back to the master by clicking back button or swiping back, they don't come back. After popping back, even the "master's" title and bar buttons are gone. I have no clue how to troubleshoot this as there are no errors.
IN my code, I am not hiding the navigation bar anywhere nor doing anything fancy with the navigation controller.
Screenshots from view hierarchy insprector:
Notice how the title and my right bar buttons on behind a few other views. the back button is at the very front. This shows that the buttons and title are not hidden, they are being covered by 3 extra views: UIVisualEffectView, _UIVisualEffectBackdropView and _UIVIsualEffectFilterView
Also in the video, you will notice that if i do a half swipe back, then cancel the swipe, the bar buttons come back. But the title doesn't.
After returning to the master, notice the master's nav bar stuff is overlaid with 2 other private class views:
I push to detail programmatically:
Relevant code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
PlaylistDetailViewController *pdvc = (PlaylistDetailViewController*)[self.storyboard instantiateViewControllerWithIdentifier:#"PlaylistDetailViewController"];
pdvc.indexPath=indexPath;
[self.navigationController pushViewController:pdvc animated:YES];
}
I ran into this problem too, and all the solutions suggested so far are either:
too complicated
doesn't work
In the end I found out that this was caused because of the updated draw cycle for UINavigationBar in iOS10.
To get around this I had to fix it with:
self.navigationController.navigationBarHidden = YES;
self.navigationController.navigationBarHidden = NO;
It's basically triggering the navigationbar to redraw.
It's still annoying how they can just push out a new version of OS that breaks something this significant.
I ran into this same issue but it was caused from using a custom UINavigationBar that was adding a blur view. It looks like something has changed with iOS10 that when adding a title or buttons to the navigation bar they are being added at a specific index instead of being appended to the subview stack.
I was able to overcome this issue by overriding the method insertSubview:atIndex and making sure the blurView was always inserted at the back of the subview stack.
I was getting the same issue like u facing now. There are some changes i did in my code and its working. In my viewWillAppear write a code of navigation in dispatch_async
dispatch_async(dispatch_get_main_queue(), ^{
//BACK BUTTON CALLING
//NAVIGATION TITLE
});
[super viewWillAppear:animated];
This will help you to set your title and back button with the help of main queue.
actually, i just figured out a minute ago. I am using a custom GKFadeNavigationController from github.com/gklka/GKFadeNavigationController AFter removing it, that fixes the issue.
Same problem applies if you are using the LTNavigationBar library (https://github.com/ltebean/LTNavigationBar)
The workaround for me was to change the code in UINavigationBar+Awesome.m:
Replace
[[self.subviews firstObject] insertSubview:self.overlay atIndex:0];
with
[[self.subviews firstObject] insertSubview:self.overlay atIndex:self.subviews.count -1];
Swift 3.0 workaround for this:
Subclass UINavigationBar and override insertSubview(_ view: UIView, at index: Int)
override func insertSubview(_ view: UIView, at index: Int) {
if let _ = view as? UIVisualEffectView {
super.insertSubview(view, at: 0)
} else {
super.insertSubview(view, at: self.subviews.count - 1)
}
}
I found a solituion for my work. Create a view (viewBackground) with all the images and colors that conform the navigation bar and then y convert it in a image and use it like a background.
UIGraphicsBeginImageContextWithOptions(viewBackground.bounds.size, viewBackground.opaque, 0.0);
[viewBackground.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[UINavigationBar appearance] setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];

How to remove navigation subview when view disapper?

I am using custom navigation view for navigation bar.
CustomNavigation *navigation = [[CustomNavigation alloc] initWithNibName:#"CustomNavigation" bundle:nil];
[self.navigationController.navigationBar addSubview:navigation.view];
This is my code for custom navigation to addsubview for navigation. I am using in viewwillapper. Because it's show and hide image and button based from popviewcontroller.
Here my problem is I need to dealloc this customnavigation view but I am already tried in view disappear it won't work? :( (I am using find that issue by "debug view hierarchy" in Hide or show debug area )
Am I using correct way for custom navigation bar or else give me correct way to create customized navigation bar?
If this is correct way to create customized navigation bar then how to dealloc this custom navigation view when view disapper?
I am new bee for xcode so give some little more explanation maybe I am struggles to understand. :(
Sample APP navigation only one at home screen also pop from another view
Sample APP at second view
My app at home screen
After few view my home screen navigation
Check all screens you will understand what I want.
I want to dealloc all navigation bar allocation form manually.
Screen shot's from "debug view hierarchy" in Hide or show debug area - XCODE.
This is worked for me :)
Add a tag for that view each time when I use add subview code before
for(UIView *view in [self.navigationController.navigationBar subviews])
{
if(view.tag == 1000 && [view isKindOfClass:[UIView class]])
{
navigation = nil;
[view removeFromSuperview];
}
}
If it's not perfect answer then show the correct one. Advance thanks.

Black status bar in ios 7 - secondary issue

I know this question has been asked several times and the solutions I have seen have been very helpful. But since i have 2 conflicting requirements, I am a little stranded and hoping to find some help.
So here are the requirements:
We have multiple View controllers out of which only one needs to be full screen (without status bar on the top).
The other view controllers need to show a black status bar with a dark gray navigation bar
The First View controller is embedded in a navigation controller.
As recommended in some of the other posts, I did the following
Set UIViewControllerBasedStatusBarAppearance to NO
Added this code in app delegate
CGRect frame = [[UIScreen mainScreen] bounds];
self.window.frame = CGRectMake(0,20,frame.size.width, frame.size.height-20);
self.window.bounds = self.window.frame;
It works fine if I only stay in those View controllers that have the status bar.
The moment I open the FULL screen view controller, that VC is cut off on the top as shown here.
Additionally when I come back to the Main view controller, now thats shifted up as well and the title bar is where the status bar was showing.
I have tried to push the views back down by resetting the view.frame and requesting layout but it doesnt take effect.
Any suggestions on how to resolve this?
Don't change self.window.bounds in app delegate. Instead, in your view controllers try something like this:
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES/NO animated:YES];
[self setNeedsStatusBarAppearanceUpdate]; // For showing/hiding status bar
[super viewWillAppear:animated];
}
- (BOOL)prefersStatusBarHidden {
return YES/NO;
}
You will have different frames for the view in ViewDidLoad according to whether status bar and navigation bar are there.

How to show/hide a search bar inside a navigation bar (iOS 7) as in Apple's Calendar app?

I want to use a search bar button in a navigation bar to show a search bar just like Apple do in the Calendar app. The cancel button would dismiss the search bar and return the navigation bar to its former state, bar buttons, title, etc.
Using the iOS 7 property:
self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
puts the search bar into the navigation bar just fine. My problem is trying to have it appear conditionally on the press of a bar button. I've tried firing this line from my button's action but no go. I've tried setActive:Animated: on the searchDisplayController
self.searchDisplayController.active = YES;
but no luck either. Any ideas or help would be appreciated.
I'm not sure if you notice, but on the Apple's calendar app when you press the search icon, it open a new UITableView with search bar. If this is what you want to do, you will have a create a UIViewController with a UITableView and a UISearchBar which inside that tableView you will be filtering the content.
If I was you, I will just hide the UISearchBar and call it whenever is needed with the button to show up.
This might work as well. Just give it a try and let me know:
In your viewWillAppear:
- (void)viewWillAppear:(BOOL)animated {
// scroll search bar out of sight
CGRect newBounds = self.tableView.bounds;
if (self.tableView.bounds.origin.y < 44) {
newBounds.origin.y = newBounds.origin.y + self.searchBar.bounds.size.height;
self.tableView.bounds = newBounds;
}
// new for iOS 7
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] atScrollPosition:0 animated:YES];}
Now that is hidden, call this to hide it again when the search is done:
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
[self viewWillAppear:YES];
}
and to show the searchBar with a button, then:
- (IBAction)displaySearchBar:(id)sender {
// makes the search bar visible
[self.searchBar becomeFirstResponder];
}
In iOS 8 you can simply present a UISearchController and you will get the same animation as Calendar.app. Check out Apple's UICatalog sample code for an example.

UISearchbar vanishes when in UIScrollView

I seem to be having an issue with the UISearchbar in iOS 7 vanishing in two scenarios. First the controller is fairly simple it has a nib which contains a scrollview which has in it the uisearch bar and some content. The ui search bar is at the top of the scrollview. So when I scroll the scrollview so the uisearchbar is longer visible and I exit and reneter the controller the uisearch bar is longer visible. Clicking the region makes it appear again. The uisearchbar also vanishes when I double tap it quickly. This controller worked fine is iOS 6 these issues are only happening now that I am building for ios 7
Edit
Investigating the double tap issue causing the uisearchbar to disappear. It seems that the uisearch bar when double tapped quickly is removing the uisearchbar from the view hierarchy when displaying it but never readding it back when it has been dismissed. So I can workaround that by doing
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
// workaround for bug in ios 7 were quickly double tapping uisearchbar (e.g it appears and get dismissed quickly)
// does not re add the uisearch bar to the correct view.
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0")) {
UIView *parentView = [self.scrollView.subviews objectAtIndex:0];
[parentView addSubview:self.searchDisplayController.searchBar];
}
return;
}
Have you tried doing some UI refresh stuff?
Like:
- (void)viewWillAppear:(BOOL)animated{
[self.scrollView setNeedsLayout];
}

Resources