iosanimationuiviewfacebook-pop

UIView Animation with POP framework grow and shrink in same action


I'm using POP framework for animations. I want to tap a UIButton and have it grow by 5%, then shrinks back to original size. I can get the grow or the shrink to work, but since I haven't used the framework I don't know how to make both happen in one action.

The animation code is below. I'm sending this code from an IBAction attached to various buttons. The following code just makes it grow.

-(void)popAnimationGrowAndShrink:(UIButton*)sender{

    const CGRect originalSize = sender.frame;

    POPSpringAnimation *animGrow = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
    POPSpringAnimation *animShrink = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
    animGrow.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, sender.frame.size.width * 1.1, sender.frame.size.height *1.1)];
    animShrink.toValue = [NSValue valueWithCGRect:originalSize];
    animGrow.springSpeed = 5;
    animGrow.springBounciness = 10;
    animShrink.springSpeed = 5;
    animShrink.springBounciness = 10;

    [sender.layer pop_addAnimation:animGrow forKey:@"grow"];
    [sender.layer pop_addAnimation:animShrink forKey:@"shrink"];
}

Solution

  • You don't have to write so much of code for this, the framework is very easy

    -(void)popAnimationGrowAndShrink:(UIButton*)sender{
    
       UIButton *btn=(UIButton*)sender;
       POPSpringAnimation *sprintAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewScaleXY];
       sprintAnimation.velocity = [NSValue valueWithCGPoint:CGPointMake(8, 8)];
      sprintAnimation.springBounciness = 20.f;
       [self.btn pop_addAnimation:sprintAnimation forKey:@"bounceAnim"];
    }