我需要知道UISearchBar的cancel按钮在调用后何时完成动画
searchBar.setShowsCancelButton(false, animated: true)我试过了
UIView.animateWithDuration(3, animations: {
self.searchBarView.searchBar.showsCancelButton = false
}, completion: {finished in
print(finished)
})但是完成块是立即触发的,任何解决方案都将不胜感激。
发布于 2016-08-16 20:03:10
您可以使用layoutIfNeeded()在UIView.animateWithDuration(...)中更新视图
尝试以下代码:
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")
})
}
}和故事板:

https://stackoverflow.com/questions/38961883
复制相似问题