为图像弹跳动画

时间:2011-08-30 05:34:41

标签: iphone xcode

我想为像弹跳的图像制作动画。我能够将它向前弹回但我无法将其推回去。 我正在使用此代码:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0f];
hair.transform = CGAffineTransformMakeScale(3.0, 3.0);
[UIView commitAnimations];

请帮帮我..我现在是结构而且无法解决这个问题。请帮助我。

3 个答案:

答案 0 :(得分:7)

使用这几行代码来动画像弹跳一样的图像。

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

 //imgView is your UIImageView where you set an image 

[self.view addSubview:imgView];

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

由于

答案 1 :(得分:3)

请注意UIView reference

  

在iPhone OS 4.0及更高版本中不鼓励使用此方法。您应该使用基于块的动画方法。

因此,在您的情况下,您可能希望实现以下内容:

[UIView animateWithDuration:2.0 animations:^(void) {
    hair.transform = CGAffineTransformMakeScale(2.0, 2.0);
} completion:^(BOOL finished) {
    if(finished){
        [UIView animateWithDuration:2.0 animations:^(void) {
            hair.transform = CGAffineTransformMakeScale(0.5, 0.5);
        }];
    }
}]; 

答案 2 :(得分:0)

您可以使用此代码,只需要调用其中一个代码,它们就会自动相互调用

- (无效)animateZoomOut {

[UIView animateWithDuration:1
                      delay:0
                    options:UIViewAnimationOptionTransitionNone
                 animations:^ {
                     self.imgGift.transform = CGAffineTransformMakeScale(0.5, 0.5);
                 }completion:^(BOOL finished) {
                     [self animateGiftZoomIn];
                 }];

} - (无效)animateZoomIn {

[UIView animateWithDuration:1
                      delay:0
                    options:UIViewAnimationOptionTransitionNone
                 animations:^ {
                     self.imgGift.transform = CGAffineTransformMakeScale(1, 1);
                 }completion:^(BOOL finished) {
                     [self animateGiftZoomOut];
                 }];

}