2015-05-06 57 views
3

我想向下面的動畫添加反彈效果。這裏是我的代碼:如何將反彈效果添加到UIView animateWithDuration

[UIView animateWithDuration:1.0 
         delay:.0 
     usingSpringWithDamping:0.5 
     initialSpringVelocity:2.0 
        options:UIViewAnimationOptionCurveEaseOut 
        animations:^{ 
         // Coming from a value of CGAffineTransformMakeScale(0.001, 1.0) 
         self.myView.transform = CGAffineTransformMakeScale(1.0, 1.0); 
        }completion:nil 
      ]; 

它工作不正常。它在動畫結束時變得更寬,然後恢復正常。我希望寬度反彈到比1.0更小的值,不超過1.0。

+0

接受的答案也PLZ –

+0

這不是我正在尋找的反彈動畫。 – Eric

+0

動畫正如其應該的那樣工作。這只是你**想要**而已。您必須在當前代碼的完成塊中添加一個簡單的'animateWithDuration:'塊。 **或**,如muku指出的那樣,使用'UIDynamicAnimator'。 – n00bProgrammer

回答

6

UST爲未來的代碼重用和保持代碼乾淨

popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001); 

[self.view addSubview:popUp]; 

[UIView animateWithDuration:0.3/1.5 animations:^{ 
    popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1); 
} completion:^(BOOL finished) { 
    [UIView animateWithDuration:0.3/2 animations:^{ 
     popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9); 
    } completion:^(BOOL finished) { 
     [UIView animateWithDuration:0.3/2 animations:^{ 
      popUp.transform = CGAffineTransformIdentity;        
     }]; 
    }]; 
}];