【问题标题】:iOS 11 UISearchController in Navigation Bar with UIRefreshControl causes layout glitch带有 UIRefreshControl 的导航栏中的 iOS 11 UISearchController 导致布局故障
【发布时间】:2018-04-23 19:35:12
【问题描述】:

我正在尝试在表格视图上使用UIRefreshControl 以及navigationItem 上的新searchController API。
现在,当我设置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
}

【问题讨论】:

    标签: uitableview uikit ios11 uisearchcontroller uirefreshcontrol


    【解决方案1】:

    我刚刚遇到了同样的问题。它绝对看起来像 UIKit 中的一个错误。这绝对是 filing a radar 值得的东西。

    不过,我找到了一种非常巧妙的方法来缓解它:

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

    基本上这里发生的情况是,每当滚动视图滚动到顶部(刷新控件将变得可见)时,这段代码会将hidesSearchBarWhenScrolling 转回YES。一旦用户再次向下滚动,它将被设置回NO,并且搜索栏将继续保持可见。

    希望 Apple 会在未来的 iOS 版本中解决此问题,但对于当前的发布版本,这可能必须这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多