How to know when a UIView animation is complete

The custom view that I created is animated by its container - in my opinion, I am updating the parts with other animations (for example, UICOllectionView)

I see it throwing errors

*** Assertion failure in -[UICollectionView _endItemAnimations

Digging around, I see that my view is related to animation:

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

So, before performing the animation operations, I check:

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

    }

and I see that the animation objects are returning:

at this point, I would like to “wait” until all animations complete before the update.

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

But it's a little dirty and hard to keep track of.

Is there an easier way to use the UIView method - a much higher level?

+3
source share
2 answers

UIView :

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

:

@property BOOL isAnimating;

isAnimating property. , . :

[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.");
    }];

, :

if (self.isAnimating)
    NSLog(@"view is animating");
+3

, :

@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);

,

0

All Articles