问题描述
我在 tableHeaderView
中有一个带有搜索栏的表格视图,由 UISearchController
管理。我使用标准的 UISearchController
演示动画。
I have a table view with a search bar in the tableHeaderView
, managed by a UISearchController
. I use the standard UISearchController
presentation animation.
我想为与searchBar动画具有相同持续时间的另一个视图设置动画。我尝试了各种持续时间值但是它们在任何时候都不完全匹配。
I want to animate another view with the same duration as the searchBar animation. I tried various duration values but alas they don't match perfectly at all times.
所以我认为使用会很棒 - [UIViewControllerTransitionCoordinator animateAlongsideTransition:完成:]
API。
So I thought it would be great to make use of the -[UIViewControllerTransitionCoordinator animateAlongsideTransition:completion:]
API.
不幸的是我找不到的引用< UIViewControllerTransitionCoordinator>
对象。具体来说, searchController.presentingViewController.transitionCoordinator
是 nil
。
Unfortunately I can't find a reference of the <UIViewControllerTransitionCoordinator>
object. Specifically, searchController.presentingViewController.transitionCoordinator
is nil
.
推荐答案
我遇到了同样的问题,我需要在 UISearchController
的演示文稿旁边制作其他视图的动画。在显示搜索控制器的调用后, transitionCoordinator
变为可用,您可以添加代码来为您的视图设置动画
I had the same problem, I needed to animate other views alongside the the presentation of the UISearchController
; After the call to present the search controller the transitionCoordinator
becomes available and you can add code to animate your views
演示:
func search() {
let searchController = UISearchController(searchResultsController: resultsController)
// Configure search controller
self.present(searchController, animated: true) {}
self.transitionCoordinator?.animate(alongsideTransition: { (context) in
// animate other views
}, completion: nil)
}
我还必须在解雇搜索控制器时动画视图,在这种情况下,我实现 UISearchControllerDelegate
的 willDismissSearchController
方法, transitionCoordinator
在此方法中无法立即使用,但进行异步调用可以解决这个问题
I also had to animate the views while dismissing the search controller, in this case I implement the willDismissSearchController
method of the UISearchControllerDelegate
, the transitionCoordinator
is not immediately available in this method but making an asynchronous call does the trick
解散:强>
func willDismissSearchController(_ searchController: UISearchController) {
DispatchQueue.main.async {
searchController.transitionCoordinator?.animate(alongsideTransition: { (context) in
// animate views
}, completion: nil)
}
}
这适用于iOS 9
这篇关于如何在UISearchController演示/解雇动画旁边制作动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!