我最近在我的 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/