Tag: uisearchbar uisearchcontroller

自定义UISearchControlleranimation

底线问题: 如何覆盖属于UISearchController的searchBar的默认animation? 标准search控制器行为: 好的,所以我试图创build一个自定义的animation,当附加到UISearchController UISearchBar成为活动。 看起来标准animation期望searchBar以占用屏幕的宽度开始。 当animation开始时,缩小search栏并淡入其右侧的取消button。 我想达到什么: 我想让我的searchBar以一个很小的状态开始,大约是屏幕宽度的一半,以允许两个button放在旁边的导航栏中。 现在animation: 当searchBar变为活动状态时,我想让animation展开searchBar,并取消button淡入。 解散animation: 当searchBar被解散时,我想要相反的animation发生:取消button淡出和searchBar收缩到原来的大小。 问题: 我find了一种通过使用UISearchControllerDelegate方法presentSearchController实现所需的呈现animation的方法: func presentSearchController(searchController: UISearchController) { // Animate Buttons UIView.animateWithDuration(0.1, animations: { // First Hide Buttons self.createMoxyButton.alpha = 0 self.centerMapButton.alpha = 0 }) // Animate Search Bar UIView.animateWithDuration(0.5, animations: { // Search Bar searchController.searchBar.frame = CGRectMake(searchController.searchBar.frame.origin.x, searchController.searchBar.frame.origin.y, self.wBounds – 40, searchController.searchBar.frame.height) self […]