我正在尝试使用 UIRefreshControl
与新 searchController
一起放在表 View 上API 上 navigationItem
.
现在当我设置 hidesSearchBarWhenScrolling
“下拉刷新”动画不再显示,刷新控件只是在某个点弹出。
它似乎是 UIKit 中的一个错误(...与每年相同的程序)。
有没有人找到解决这个问题的方法?
要重现该问题,请将其添加到新的 iOS 11“主/详细信息”示例项目中:
- (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
}
最佳答案
我刚刚遇到了同样的问题。它绝对看起来像是 UIKit 中的一个错误。这肯定是 filing a radar将是值得的。
不过,我发现了一种非常hacky的方法来缓解它:
- (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;
}
}
基本上这里发生的事情是,每当 ScrollView 滚动到顶部(刷新控件将变得可见)时,这段代码就会变成
hidesSearchBarWhenScrolling
返回 YES
.一旦用户再次向下滚动,它将被设置回 NO
并且搜索栏将继续保持可见。希望 Apple 会在 future 的 iOS 版本中修复这个问题,但对于当前的出货版本,这可能是必须的。
关于uitableview - 带有 UIRefreshControl 的导航栏中的 iOS 11 UISearchController 导致布局故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47225040/