gpt4 book ai didi

swift - UISearchBar 显示取消按钮动画完成

转载 作者:搜寻专家 更新时间:2023-10-31 22:45:17 26 4
gpt4 key购买 nike

我需要知道 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")
})
}
}

和 Storyboard: enter image description here

关于swift - UISearchBar 显示取消按钮动画完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38961883/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com