3
votes

A custom view I created is being animated by its container - in my view I update portions of the subviews with other animations (for instance a UICOllectionView)

I see that this is throwing errors

*** Assertion failure in -[UICollectionView _endItemAnimations

Digging around I see that my view has animations attached to it:

<GeneratorView: 0x15b45950; frame = (0 0; 320 199); animations = { position=<CABasicAnimation: 0x145540a0>; }; layer = <CALayer: 0x15b49410>>

So now before performing animation operations I check:

NSArray *animationKeys = [self.layer animationKeys];
    for (NSString *key in animationKeys) {
        CAAnimation *animation = [self.layer animationForKey:key];

    }

and I see that animation objects are returned:

at this point I would like to "wait" until all animations have completed before updating self.

I see that I can add myself as the CAAnimation delegate.

But this is a bit messy and hard to track.

Is there an easier way using a UIView method - much higher level?

2
Which method do you use to animate the view?Greg
I'm not animating - the container is - I want to know when my view (self) is NOT animating - i.e if (self is animating) { wait for it to stop animating } now do some animations;Avner Barr
The animations in the question i posted are performed by some other object - on the view - now the view want to animate its subviews when these animations have completedAvner Barr

2 Answers

3
votes

You can use UIView method to do the animation in the container:

[UIView animateWithDuration: animations: completion:];
[UIView animateWithDuration: delay: options: animations: completion:];

You should add properties to your custom view:

@property BOOL isAnimating;

In the container run the animation block and change view isAnimating property. This method accept block which will be fired when the animation complete. Example:

[UIView animateWithDuration:1.0 animations:^{
        //Your animation block
        view1.isAnimating = YES;
        view1.frame = CGRectMake(50.0f, 50.0f, 100.0f, 100.0f);
        // etc.
    }completion:^(BOOL finished){
        view1.isAnimating = NO;
        NSLog(@"Animation completed.");
    }];

Now it your view you can see if the view is animating:

if (self.isAnimating)
    NSLog(@"view is animating");
0
votes

Ithink you can you that :

@interface UIView(UIViewAnimationWithBlocks)

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);

Hope that will help