2011-08-30 99 views
1

我想動畫像彈跳一樣的圖像。我能夠反彈它,但我不能推回來。 我使用這個代碼:彈跳圖像的動畫

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

請幫我..我早上結構在這一點上並沒有能夠解決這個problem.Please幫助我。

回答

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); 
     }]; 
    } 
}]; 
6

使用的代碼,這幾行獲得動畫的圖像一樣彈跳。

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

這解決了我的問題..謝謝... –

+1

@Sunil,是的,它的工作原理完全按照我的期望。 – Girish

0

您可以使用此代碼,您只需要調用其中的一個,他們會打電話給對方自動

- (無效)animateZoomOut {

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

} - (void)animateZoomIn {

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

}