Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Modifying activeAnimations while enumerating through it #3

@Naxum

Description

@Naxum

Howdy! Not sure if I'm going about this in a weird way, but I must be somehow calling the addAnimation/removeAnimationWithID while tickActiveAnimations is being called, making my app crash.

My basic solution is to make two more collections that modify activeAnimations after it's done looping.

@property (nonatomic, strong) NSMutableArray *animationsToAdd;
@property (nonatomic, strong) NSMutableDictionary *animationsToRemove;

Insert/remove the animations immediately after the for loop in tickActiveAnimations

for (JotINTUAnimation *anim in self.animationsToAdd) {
    anim.startTime = CACurrentMediaTime();
    [self.activeAnimations setObject:anim forKey:@(anim.animationID)];
}

for (NSNumber *animationID in [self.animationsToRemove keyEnumerator]) {
    JotINTUAnimation *animation = [self.activeAnimations objectForKey:animationID];
    [animation complete:[[self.animationsToRemove objectForKey:animationID] boolValue]];
    [self.activeAnimations removeObjectForKey:animationID];
    if ([self.activeAnimations count] == 0) {
        self.displayLink.paused = YES;
    }
}

[self.animationsToRemove removeAllObjects];
[self.animationsToAdd removeAllObjects];

Rewrite the basic addAnimation and removeAnimationWithID methods

- (void)addAnimation:(JotINTUAnimation *)animation
{
    if ([self.activeAnimations count] == 0) {
        self.displayLink.paused = NO;
    }

    [self.animationsToAdd addObject:animation];
}

- (void)removeAnimationWithID:(JotINTUAnimationID)animationID didFinish:(BOOL)finished
{
    [self.animationsToRemove setObject:@(finished) forKey:@(animationID)];
}

This is my first issue I've ever created, if you want me to submit a PR let me know. Also, if I am totally overengineering this problem, let me know that as well :D

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions