uitableview - 带有 UIRefreshControl 的导航栏中的 iOS 11 UISearchController 导致布局故障

标签 uitableview uikit ios11 uisearchcontroller uirefreshcontrol

我正在尝试使用 UIRefreshControl与新 searchController 一起放在表 View 上API 上 navigationItem .
现在当我设置 hidesSearchBarWhenScrolling “下拉刷新”动画不再显示,刷新控件只是在某个点弹出。

enter image description here

它似乎是 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/

相关文章:

ios - 未捕获的异常 'NSRangeException' ,原因 : '*** -[__NSArrayI objectAtIndex

iOS 10 - 导航栏 NSInternalInconsistencyException

ios - UICollectionView io11 - 顶部插图

ios - 在仅查看模式下使用 PDF Kit 加载 pdf

iphone - 向使用字母部分的 iPhone 应用程序添加搜索栏?

swift - 'ViewController' 不符合协议(protocol) 'UITableViewDataSource' swift

ios - iOS程序化分组表为空

ios - 如何通过多个 VC 访问公共(public)内存位置?

objective-c - 如何将 NSString 对象中的字符转换为 UILabel 对象?

objective-c - 我发现 tableview 无法在 iOS 11 中滚动