UISearchController打开后,iOS 13无法滚动到底部

问题描述 投票:0回答:1

[在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个回答
0
投票

尝试一下

Swift:

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
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.