ios - UITableView 在激活和停用 UISearchController 时在位置之间跳转

标签 ios objective-c uitableview uikit uisearchcontroller

我最近在我的 TableView 中添加了一个 UISearchController,但我遇到了一个动画问题。当搜索栏被点击并变为事件状态时, TableView 会跳起来以满足搜索 Controller 的新(事件)位置。这个问题是搜索 Controller 动画到这个新位置,但 TableView 没有,所以它很不和谐。 Here is a video的问题。

TableView 的顶部约束设置为 View Controller 的安全区域。下面是我为配置搜索 Controller 而编写的代码:

- (void)configureSearchController {
    UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    searchController.searchResultsUpdater = self;
    searchController.obscuresBackgroundDuringPresentation = NO;
    searchController.searchBar.placeholder = @"Search for any cryptocurrency";
    self.searchController = searchController;
    if (@available(iOS 11.0, *)) {
        self.navigationItem.searchController = searchController;
    } else {
        self.navigationItem.titleView = searchController.searchBar;
    }
    self.definesPresentationContext = YES;
}

有人对我如何使过渡顺利进行有任何建议吗?理想情况下,我希望表格 View 以与搜索 Controller 相同的速度向上移动,因为这是整个 iOS 的默认行为。

最佳答案

从视频中我认为表格 View 没有延伸到导航栏下方。如果您真的允许它这样做,您可能可以避免这种跳跃。

你还应该设置

tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic

使其contentInsets自动调​​整。

关于ios - UITableView 在激活和停用 UISearchController 时在位置之间跳转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49098249/

相关文章:

ios - Azre iOS 客户端 SDK 中的乐观并发

ios - 无法选择 UITextField

ios - Flash 滚动指示器不工作

ios - AdMob 在已发布的应用程序中显示测试插页式广告

ios - 应用程序在同一个 'UITableViewCell' 中出现两个自定义 'UITableView' 崩溃

swift - Swift 3 中的 TableViewCell 复制属性已更改

swift - 如何将 TableView 部分的选定索引添加到数组

ios - Swift 4 + 调配 viewWillAppear()

iphone - 取消通话后返回应用程序

ios - 混合静态和动态 UITableViewController 内容会导致 NSRangeException