我需要知道 UISearchBar 的取消按钮在调用后何时完成他的动画
searchBar.setShowsCancelButton(false, animated: true)
我试过了
UIView.animateWithDuration(3, animations: {
self.searchBarView.searchBar.showsCancelButton = false
}, completion: {finished in
print(finished)
})
但是会立即触发完成 block ,任何解决方案都将不胜感激
最佳答案
您可以使用 layoutIfNeeded() 来更新 UIView.animateWithDuration(...) 中的 View
试试这段代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet var searchBar: UISearchBar!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func touchUpInside(sender: UIButton) {
searchBar.showsCancelButton = !searchBar.showsCancelButton
UIView.animateWithDuration(3, animations: {
self.searchBar.layoutIfNeeded()
}, completion: {finished in
print("Animation finished")
})
}
}
关于swift - UISearchBar 显示取消按钮动画完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38961883/