首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UISearchBar showsCancelButton动画制作完成

UISearchBar showsCancelButton动画制作完成
EN

Stack Overflow用户
提问于 2016-08-16 03:41:07
回答 1查看 594关注 0票数 3

我需要知道UISearchBar的cancel按钮在调用后何时完成动画

代码语言:javascript
复制
searchBar.setShowsCancelButton(false, animated: true)

我试过了

代码语言:javascript
复制
UIView.animateWithDuration(3, animations: {
    self.searchBarView.searchBar.showsCancelButton = false
         }, completion: {finished in
         print(finished)
})

但是完成块是立即触发的,任何解决方案都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-16 20:03:10

您可以使用layoutIfNeeded()在UIView.animateWithDuration(...)中更新视图

尝试以下代码:

代码语言:javascript
复制
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")
    })
}
}

和故事板:

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38961883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档