UISearchbar vanishes when in UIScrollView - ios

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];
}

Related

iOS 10 - View Controller / Navigation Bar Title hidden

I'm currently facing stranges behaviours with iOS 10.
Indeed, everything was working fine, but since I updated to xCode 8 and began testing my App on iOS 10, a lot of stuff went wrong.
For example, all my Navigation Bar's titles are not displayed anymore.
More precisely, when I'm using the menu to navigate threw my app, every time I switch to a different view, there are no title, BUT when I press the back button, I can briefly see it before the transition to the other view.
I don't understand this new behaviour, I didn't change anything in the code, and when I launch the App on iOS 9 or lesser, everything is working properly.
I tried to set the title in the ViewWillAppear / ViewDidLoad, in the prepareForSegue, but nothing is working.
if ([segue.identifier isEqualToString:kMy_Segue]) {
MyViewController* destinationVC = segue.destinationViewController;
[destinationVC setTitle:#"MyTitle"];
}
I feel like there are some changes with the pushed Navigation Controller, or the title item is not at the same index than the Navigation Bar itself because when I navigate threw subviews in the menu, the title only appears when I press back.
For example I have a category in my Menu called "World".
When I tap it I want the title of the subview to be "World", but nothing is displayed. Then, I have all the continents listed "Africa", "Europe", "Asia" etc...
When I tap on Africa, I want the next title to be "Africa" right?
And again, nothing is displayed BUT if I press the back button and go back to the list of continents, the title "World" appears.
If anyone has encountered this issue, I would really appreciate some help.
Follow this:
Solution-1
Goto to the viewController, then click on NavigationItem as shown below:
In the right pane, change "Title" as follows:
Solution-2
Add a UIView to your navigationBar as shown below:
Add an UILabel to your navigationItem as shown below:
Change the frame of the newly added UILabel as follows:
Change text of UILabel to "Sample Title" and change UIView backgroundColor to clearColor.
I have made a sample in Xcode8, please check my GitHub link below:
https://github.com/k-sathireddy/NavigationItemSample
Have you try to adding navigation item on to your navigation bar? You'r using Storyboard for this design.
I found a solution to my issue. It's really weird.
I have a fade animation to the navigation bar on the Home Page.
It's a scroll view so that when I scroll down I can still see the title and the navigation bar.
On iOS < 10, the fade animation only change the background color and transparency. But when I launch the app on iOS 10, the fade effect hide everything, the menu icon, the title, everything. I believe Apple changed the structure of the navigation bar items.
Moreover, when I tap on the menu icon to navigate threw my App when the fade animation is on going, I can see that the title and the navigation bar items are under "fade effect" and even for the next ViewControllers's title after my navigation.
So it's working, it's just that the menu icon, titles etc.. are hidden on the Navigation Bar.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
UIColor * color = [Constants backgroundColor];
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat threshold = 250;
if (offsetY > threshold) {
[self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:1]];
} else {
CGFloat alpha = offsetY / threshold;
[self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:alpha]];
}
}
I guess the issue is coming from the library LTNavigationBar that I used to change the appearance of the NavigationBar dynamically...

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];

UITableView as ScrollView Between Navigation and Tab Bars

I have a table view laid out between a navigation bar and a tab bar and want to achieve scrolling only for the table view section (so in other words, in my iOS Simulator, I would want the two bars to always be seen, and I should be able to scroll my table view between them).
Having tried out various suggestions from SO posts, afraid am still getting something wrong. Can you advise please how do I fix this issue - I've been struggling with it for the last 1 day!
In the table view controller's viewDidLoad, I use the following code. Earlier, I also tried initializing a scroll view separately but understand that table view is a sub-class of scroll view, so ditched that path...
- (void)viewDidLoad
{
[super viewDidLoad];
// To remove extra separators from the table view to prevent blank rows from showing.
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
// ***** Scroll view implementation *****
[[self tableView] setFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - self.navigationController.navigationBar.frame.size.height - self.tabBarController.tabBar.frame.size.height)];
[[self tableView] setContentSize:CGSizeMake(self.view.frame.size.width, 2000)];
[self setEdgesForExtendedLayout:UIRectEdgeNone];
self.automaticallyAdjustsScrollViewInsets = YES;
}
In fact, to test this further, I have created a scroll view in a separate tab (in this tabbarcontroller app) where I only have a navigation bar and a tab bar so far (no table view). Its viewDidLoad looks like this - somehow, no luck there as well... the scroll bar starts from the top of the screen (rather than from the bottom of the navigation bar) and goes till the bottom of the screen (rather than till the top of the tab bar). So clearly I'm doing something conceptually wrong here... appreciate if you can help out please!!! The numbers put in here are experimental to test this out but I've ensured that the content size is larger than the scroll view frame...
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 300)];
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width, 1500)];
[self.view addSubview:scrollView];
[self setEdgesForExtendedLayout:UIRectEdgeNone];
self.automaticallyAdjustsScrollViewInsets = NO;
[scrollView setScrollEnabled:YES];
}
Finally, when I debug my app in the simulator, what is odd is that for the table view tab, the scroll bar does appear momentarily to start from below the navigation bar. But as soon as I touch the track pad to scroll, it disappears and a more prominent scroll bar appears and starts from the top of screen to the bottom of the screen as I mention initially above!
I think I found the underlying error in my ways. More than an implementation bug, it was me missing out on a very basic issue...
In summary, the iOS Simulator would typically always have higher resolution / number of pixels than the computer screen, and no matter what, the simulator would always outsize the computer screen unless manually resized. So the scroll bar would usually be always present. This SO post helped me understand it.
On the other hand, the UIScrollView was automatically already implemented in my table view, given that UITableView is a subclass of UIScrollView - I didnt have to do anything. I was scrolling the simulator with a 'light' double-touch, which was taking me to the scroll bar due to the issue mentioned above. If I 'hard-clicked' and then scrolled, then voila! The required UIScrollView did work properly as expected! This is probably what misled me to mention these statements in the question...!
Finally, when I debug my app in the simulator, what is odd is that for the table view tab, the scroll bar does appear momentarily to start from below the navigation bar. But as soon as I touch the track pad to scroll, it disappears and a more prominent scroll bar appears and starts from the top of screen to the bottom of the screen as I mention initially above!

UISearchController's searchbar is not responding

I am not able to get responding events on tapping UISearchController's search bar in iOS 8.
I am displaying custom view with dim background like alert view appearance, on pressing button in a view, where custom view has UISearchController's search bar as sub view. Programmatically added searchController. When I try to touch search bar, it is not responding in iOS 8 whereas I have added search bar with UISearchDisplayController for iOS 7, it is working fine.
I have viewController A with navigation bar. In viewController A, I have a button. On pressing button, I am trying to show view as custom view with dim background like alert view appearance. So I have added following line in button method.
class_name *view = [[class_name alloc] initWithNibName:#"xib_name" bundle:nil];
[self.navigationController.view addSubview:view];
Xib file of class_name has dim background with subviews like searchController's search bar.
Instead of
[self.navigationController.view addSubview:view];
added
[self presentViewController:view animated:YES completion:nil];
UISearchController's search bar is working now but i am not able to get transparent background view, instead black background appears.
I need to display previous views content and on top that current views content like alert view.
Please guide me in objective-C.

iOS 7 UISearchDisplay controller is hiding Navigation controller's bar

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.

Resources