0
votes

Because of network issues, there's a possibility i'm calling a UIView animate function twice. Somehow that seems to mess up the finished boolean you get in the completion block.

During the animation I move a UIView off screen. At the end of the animation it should set the frame i'm animating to hidden. I notice that the finished BOOL in the completion block is always set to YES. So when I call the animation for the second time, before the first call to the animation is finished, it will set to BOOL to finished, even though i expect it to be set to NO as the animation was interrupted by a new call to that same animation.

    [UIView animateWithDuration:animated ? VOTE_ANIMATION_DURATION : 0.0 delay:2 options:UIViewAnimationOptionCurveEaseOut animations:^{
    self.waitingView.frame = CGRectMake(self.waitingView.frame.origin.x, (-self.waitingView.frame.size.height) - WAITINGVIEW_SHADOW_HEIGHT, self.waitingView.frame.size.width, self.waitingView.frame.size.height);

}                completion:^(BOOL finished) {
    if (finished) {
        DDLogInfo(@"set VotingView Animation is finished");
        self.waitingView.hidden = YES;
    }
}];

I tried adding the following line too, but did not help.

 [UIView setAnimationBeginsFromCurrentState:YES];

Any clues?

1
You should use UIViewAnimationOptionBeginFromCurrentState instead of the method call. But that is not the solution here.Leo Natan
can you reduce delay to 0.0f?Kawa

1 Answers

0
votes

Well, you could set a Boolean "isAnimating" property in your class and start the animation only when it's FALSE.

if (!self.isAnimating) {
    [UIView animateWithDuration:animated ? VOTE_ANIMATION_DURATION : 0.0 delay:2 options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.isAnimating = YES;
        self.waitingView.frame = CGRectMake(self.waitingView.frame.origin.x, (-self.waitingView.frame.size.height) - WAITINGVIEW_SHADOW_HEIGHT, self.waitingView.frame.size.width, self.waitingView.frame.size.height);
    }              
    completion:^(BOOL finished) {
        if (finished) {
            DDLogInfo(@"set VotingView Animation is finished");
            self.waitingView.hidden = YES;
            self.isAnimating = NO;
        }
    }];
}

Of course this will work only if you don't need the animation to be played twice at the same time.