0

I want to know how to detect when a UISearchBar has completed animating. In iOS7, when you tap on some searchbar, the magnifying glass will shift from center to left. When endEditing becomes true, the magnifying glass then shifts back to center. I want to remove the searchbar from my UINavigationItem once the latter mentioned animation completes.

Other related SO suggestions did not seem to apply to animations of standard UIKit items... These suggestions include use of:

(void)animationDidStop:(NSString*)animationID finished:(BOOL)finished context:(void *)context

or

while([[self.view.layer animationKeys] count] > 0)

Thank you for your help!

OneManBand
  • 528
  • 5
  • 24
  • Did you try either of those things? – i_am_jorf May 08 '14 at 14:54
  • 2nd, yes. 1st, no - I don't know how to retrieve the CAAnimation of a searchbar; I assumed this method was useful for custom animations only. If thats all there is to it though, I would accept an answer showing how to use animationDidStop with a UIKit item. – OneManBand May 08 '14 at 15:06
  • http://stackoverflow.com/a/16368679/341994 – matt May 08 '14 at 15:14
  • That's pretty neat. Thank you, matt! Answer is above ^ in conjunction with http://stackoverflow.com/a/9049477/2418006 for an explanation of how to use it. :) – OneManBand May 08 '14 at 15:36
  • The only complaint I have now is that there is a momentary but noticeable lag after the searchbar animation has completed before it is removed. – OneManBand May 08 '14 at 15:41
  • @matt, I did not know about the `CATransaction` `setCompletionBlock:` method. Very cool. Thanks for pointing it out. Why don't you post that as an answer, so the OP can accept it, and we can up-vote it? I was thinking through a process of creating a custom subclass of UISearchBar that uses +layerClass to declare a custom subclass of CALayer as it's layer class, then a custom layer class that overrides `addAnimation:forKey:` to set a delegate, blah-blah-blah. The CATransaction setCompletionBlock approach is a **whole** lot simpler and cleaner. – Duncan C May 08 '14 at 16:01

0 Answers0