我有一个 UITableViewController 的子类。我有代码可以在我的 tableView 的 tableHeaderView 中添加/删除 UISearchBar。这是我必须执行这些任务的代码:
self.tableView.tableHeaderView = uiSearchBar; //Make the search bar appear
self.tableView.tableHeaderView = nil; //Make the search bar disappear
问题是我希望添加/删除 UISearchBar 是动画的;当我添加它时从顶部滑入 View ,然后当我删除它时向上滑动并滑出 View ,而不是仅仅出现和消失。有什么建议吗?
谢谢。
最佳答案
我终于弄明白了。结果很简单。我没有将 UISearchBar 添加到表头,而是使用动画 UITableViewRowAnimationTop 将它插入到表的第一个单元格中,并使用相同的方法将其删除。这导致条从顶部滑入和滑出。这是使栏出现的代码:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.baseUiTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
[self.baseUiTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
下面是删除搜索栏的代码:
[uiSearchBar resignFirstResponder];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.baseUiTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
关于iphone - 动画添加/删除 UISearchBar 到/从 UITableView tableViewHeader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1319567/