2016-08-15 6 views
2

どんな解決策もありますUISearchBar showsCancelButtonアニメーション完全

+0

は 'プリント(完成品)'以上にわたって閉鎖式を使用します。あなたはメンバーを追加することができます 'cancelDoneAnimating'とあなたの閉鎖でそれをtrueに設定します。多分最も効率的ではないかもしれませんが、別の関数がそのメンバーにアクセスしてステータスを確認することができます – NonCreature0714

+0

私はクロージャーにメンバーを追加してtrueに設定し、メンバー値が真になったときにトリガーされる関数を書いていますアニメーションの終わりに呼び出される? (完了ブロックがすぐにトリガーされたとみなして) – Ezechiele

+0

あなたの意見があります。私は、醜い解決策は、アニメーションと同じ時間の長さであるクロージャに遅延を追加し、次にメンバーを真に設定することだと思います。 – NonCreature0714

答えて

1

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") 
    }) 
} 
} 

と絵コンテ: enter image description here

+0

素晴らしいです、ありがとうございます! – Ezechiele

+0

あなたは大歓迎です! –

関連する問題