2016-01-28 104 views
0

我使用動畫的POP框架。我想挖掘一個UIButton並讓它增長5%,然後縮小回原來的大小。我可以讓增長或縮減工作,但由於我沒有使用框架,我不知道如何使兩者都發生在一個行動。UIView動畫與POP框架在同一動作中增長和縮小

動畫代碼如下。我從連接到各種按鈕的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"]; 
} 

回答

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"]; 
} 
相關問題