繁体   English   中英

iOS 13 UISearchController 一打开就不能滚动到底部

[英]iOS 13 can't scroll to bottom as soon as UISearchController opens

在 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 秒之外,这似乎是不可能的。

尝试这个

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)
    }
}

超频:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM