I am trying to use UIRefreshControl
on a table view together with the new searchController
API on navigationItem
.
Now when I set hidesSearchBarWhenScrolling
the "pull down to refresh" animation is not showing anymore and the refresh control just pops in at a certain point.
It appears to be a bug in UIKit (...same procedure as every year). Did anyone find a solution for this one?
To reproduce the issue add this to a fresh iOS 11 "master/detail" sample project:
- (void)viewDidLoad {
// [setup code here]
self.refreshControl = [UIRefreshControl new];
self.navigationItem.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.navigationItem.hidesSearchBarWhenScrolling = NO; // <-- setting this causes jumpy UI
}
I just experienced the same problem. It definitely looks like a bug in UIKit. It would definitely be something filing a radar would be worth.
I found a very hacky way to mitigate it though:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//Fixes a bug in UIKit where the refresh control is broken when `hidesSearchBarWhenScrolling` is NO.
if (@available(iOS 11.0, *)) {
self.navigationItem.hidesSearchBarWhenScrolling = scrollView.contentOffset.y < -scrollView.adjustedContentInset.top;
}
}
Basically what's happening here is that whenever the scroll view scrolls past the top (where the refresh control would become visible), this bit of code will turn hidesSearchBarWhenScrolling
back to YES
. Once the user scrolls back down again, it will be set back to NO
and the search bar will continue to remain visible.
Hopefully Apple will fix this in a future iOS version, but for current shipping versions, this will probably have to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With