我正在使用POP
框架制作动画。我想点按UIButton
并使其增长5%,然后缩小回原始尺寸。我可以让增长或缩小工作,但由于我没有使用框架,我不知道如何在一个动作中发生两者。
动画代码如下。我从附加到各种按钮的IBAction
发送此代码。以下代码使它成长。
-(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"];
}
答案 0 :(得分:1)
您不必为此编写这么多代码,框架非常简单
-(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"];
}