5

I have two animations running; show search bar and show banner. Both those animations are resizing the same view and if they are running on the same time (Which they are) the latest animation will cancel the resize. Is there anyway to check if UIView is currently animating and then standby for animation?

I'm pretty sure I'm not using CAAnimations, since Cocoa not is detecting such class.

This one is running when an ad was received. Unfortunately, that is the same time as ShowSearch is running.

- (void)adViewDidReceiveAd:(GADBannerView *)bannerView {
    if (!hasloaded) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration: 1.0];

        [bannerView_ setFrame:CGRectMake(0, self.view.frame.size.height, bannerView_.frame.size.width, bannerView_.frame.size.height)];

        // move and grow
        [bannerView_ setFrame:CGRectMake(0, self.view.frame.size.height-50, bannerView_.frame.size.width, bannerView_.frame.size.height)];
        // set original position
        [UIT setFrame:CGRectMake(UIT.frame.origin.x, UIT.frame.origin.y, UIT.frame.size.width, UIT.frame.size.height)];

        // move and grow
        [UIT setFrame:CGRectMake(UIT.frame.origin.x, UIT.frame.origin.y, UIT.frame.size.width, UIT.frame.size.height-50)];

        [UIView commitAnimations];
        hasloaded = true;
    }
}
paulmelnikow
  • 16,895
  • 8
  • 63
  • 114
Hedam
  • 2,209
  • 27
  • 53
  • Got it running with `- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)` – Hedam Mar 11 '12 at 16:19

2 Answers2

2

You can use the completion block in the UIView method +animateWithDuration:animations:completion: (which is a more modern alternative to beginAnimations/commitAnimations) to chain multiple animations (I'm guessing this is what you want to do?).

omz
  • 53,243
  • 5
  • 129
  • 141
  • No, more like just waiting for the other animation to complete with a code like `while(UIView.isAnimating == YES){ //WAIT }` – Hedam Mar 11 '12 at 16:08
  • So you want to do nothing while the animation runs and start doing something when it completes? Why not use the completion block? I don't really see the difference. – omz Mar 11 '12 at 16:13
  • 1
    I didn't knew that existed though. – Hedam Mar 11 '12 at 16:26
0

If you select your code while entering it and press control + K, you will preserve formatting and make it pretty. Try it. Reading the wall of text made from pasting code into a true-type non-color-formatted environment.

Nick Weaver says:

A UIView has a layer (CALayer). You can send animationKeys to it which will give you an array of keys which identify the animations attached to the layer. I suppose that if there are any entries, the animation(s) are running. If you want to dig even deeper have a look at the CAMediaTiming protocol which CALayer adopts. It does some more information on the current animation.

shim
  • 9,289
  • 12
  • 69
  • 108
RGuy8032
  • 71
  • 8