Pregunta

I have a UIView that acts as a badge in my app, upon pressing a button, the badge is supposed to blink into existence and then do a nice squash and stretch animation. The animation works perfectly on iPhone 4, iPhone 4s, and iPhone 5 but the 8GB iPod touch (4th Generation) iOS 5.1.1 has a really bad stuttering effect.

The popWithDuration: method causes stuttering while the resetCount method, causes the view to explode in size. Wondering if anyone knows any fixes or workarounds.

Here are the relevant methods, the class is a subclass of UIView.

- (void)popWithDuration:(CGFloat)duration
{
    if(self.canAnimateLikedNumber)
    {
        if(self.waitingToReset){
            [self resetCount];
            return;
        }
        else
            self.canAnimateLikedNumber = FALSE;

        CGAffineTransform stretchTransform = CGAffineTransformMakeScale(1.5,1.5);
        CGAffineTransform squashTransform = CGAffineTransformMakeScale(1.0,1.0);

        [UIView animateWithDuration:duration delay:0.0f options:UIViewAnimationOptionLayoutSubviews animations:^{
            [self setAlpha:1.0f];
            [self setTransform:stretchTransform];
        } completion:^(BOOL finished) {
            [UIView  animateWithDuration:0.2f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{
                [self setTransform:squashTransform];
            } completion:^(BOOL finished) {
                self.canAnimateLikedNumber = TRUE;
                if(self.waitingToReset){
                    [self resetCount];
                    return;
                }
            }];
        }];
    }

}

- (void) resetCount
{
    if([NSString isValid: self.savedCountLabel.text] || (!self.hidden && self.superview))
    {
        if(self.canAnimateLikedNumber)
        {
            self.canAnimateLikedNumber = FALSE;

            CGSize defaultSize = [NotificationBadge DefaultBadgeSize];

            CGRect originalRect = CGRectMake(self.frame.origin.x, self.frame.origin.y, defaultSize.width, defaultSize.height);
            [UIView animateWithDuration:0.2 delay:0.0f options:UIViewAnimationOptionLayoutSubviews animations:^{ //squash and stretch
                [self setTransform:CGAffineTransformMakeScale(2, 2)];
            }
            completion:^(BOOL finished)
            {
                [UIView animateWithDuration:0.4 delay:0.0f options:UIViewAnimationOptionLayoutSubviews animations:^{
                    [self setTransform:CGAffineTransformMakeScale(0.0,0.0)];
                    [self setAlpha:0.0f];
                }
                completion:^(BOOL finished)
                {
                    [self setHidden:TRUE];
                    [self setTransform:CGAffineTransformMakeScale(1.0,1.0)];

                    [self setFrame:originalRect];
                    [self.savedCountLabel setText:@"0"];
                    [self.savedCountLabel setFrame:CGRectMake(NOTIFICATION_LABEL_INSETS.left, NOTIFICATION_LABEL_INSETS.top, defaultSize.width - NOTIFICATION_LABEL_INSETS.left - NOTIFICATION_LABEL_INSETS.right, defaultSize.height - NOTIFICATION_LABEL_INSETS.top - NOTIFICATION_LABEL_INSETS.bottom)];

                    self.canAnimateLikedNumber = TRUE;
                    self.waitingToReset = FALSE;

                }];
            }];
        }
        else
        {
            self.waitingToReset = TRUE;
        }
    }
}
¿Fue útil?

Solución

Figured it out. Apparently if you use the transform property in iOS 5.0+ you cannot set the transform value to 0.0f ever.

Crediting animation working in iOS6, buggy in iOS5

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top