【问题标题】:iOS 13 can't scroll to bottom as soon as UISearchController opensUISearchController 打开后,iOS 13 无法滚动到底部
【发布时间】:2019-10-05 19:14:41
【问题描述】:

在 iOS 13 中,当您打开 UISearchController 时,它会立即显示 tableView 内容。我希望能够一直滚动到底部(比如我们有一百个项目),并在 UISearchController 出现后立即向用户显示 tableView 底部的内容。但这在 iOS 13 中是不可能的。当我在 willPresentSearchController 或 didPresentSearchController 中调用其中一个时,setContentOffset 或 scrollToRowAtIndexPathh 不能完全工作。我不敢相信它甚至在 didPresentController 中都不起作用!但是我可以在 didPresentController 之后 0.3 秒调用它们中的任何一个,它会一直滚动到底部。但我不希望我的用户在呈现 UISearchController 滚动到底部后等待 0.3 秒。我希望它在 UISearchController 显示时已经立即滚动到底部而没有任何闪烁或动画。

我正在使用 UISearchBar 来呈现 UISearchController。一旦您点击 UISearchBar,它就会向上移动到导航栏并淡入全屏 tableView 以进行搜索。

我发现在 UISearchController 的内容显示之前滚动到底部是不可能的。也许唯一的运气就是等待苹果修复。我很想听听是否有人能解决这个问题。我能够在 iOS 11 中强制执行此操作。在 iOS 12 中,我在 UISearchController 出现后做了一个动画滚动。在 iOS 13 中,除了等待 0.3 秒之外,这似乎是不可能的。

【问题讨论】:

    标签: ios uisearchcontroller ios13


    【解决方案1】:

    试试这个

    斯威夫特:

    private func moveTableViewToBottom(indexPath: IndexPath) {
        tableView.scrollToRow(at: indexPath, at: .bottom, animated: false)
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
            self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: false)
        }
    }
    

    OC:

    - (void)scrollToBottomAnimated:(BOOL)animated {
    
    NSInteger rows = [self.tableView numberOfRowsInSection:0];
        if (rows > 0) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rows-1 inSection:0];
            [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:animated];
            if (@available(iOS 13.0, *)) {
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:animated];
                });
            } else {
                // Fallback on earlier versions
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-05
      • 1970-01-01
      • 2012-09-29
      • 2013-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-27
      相关资源
      最近更新 更多