我有一个 SearchBar,并试图让它表现得像你在 iPhone 设置中看到的那样。当它被点击时,动画会平滑地将放大镜从搜索栏的中间过渡到搜索栏的左侧,并平滑地引入取消按钮。但是,当我按下取消时,动画会冻结,然后跳回正常状态,搜索图标位于栏的中间,取消按钮隐藏(参见 GIF 预览)。我的代码中有什么东西让这种情况发生吗?这是搜索条形码:
func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
searchBar.setShowsCancelButton(false, animated: true)
}
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
self.view.endEditing(true)
searchBar.setShowsCancelButton(false, animated: true)
}