开发者

bouncing animation for image

I want to animate an image like bouncing.I am able to bounce it forward but I am not able to push it back. I am using this code:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0f];
hair.transform = CGAffineTransformM开发者_如何学编程akeScale(3.0, 3.0);
[UIView commitAnimations];

Please help me out ..I am struct at this point and not able to solve this problem.Please help me.


Use these few line of code to get animate an image like bouncing.

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

Thanks


Please note that from UIView reference:

Use of this method is discouraged in iPhone OS 4.0 and later. You should use the block-based animation methods instead.

So in your case you might want to implement something like:

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


you can use this code, you just need to call one of them, and they will call each other automatically

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

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜