Cris
Cris

Reputation: 12204

Zoom in and out to a UIImage

I need to make an animation to a UIImage according to an audio file; when the sound starts i need to make a zoom to a certain point and then to apply the same animation for zooming out. I've tried to apply CGAffineTransformMakeScale but it does not make an animation. Which is the right way to apply a zoomin/out to an image?

Upvotes: 2

Views: 1285

Answers (1)

Yonathan Jm
Yonathan Jm

Reputation: 442

put the image in a UIImageView, and then use uiview animation, re-set the frame

example :

at first, you deploy the image as usual

 UIImage *myImg = [UIImage imageNamed:@"myImage.png"];
    UIImageView *myImgView = [[UIImageView alloc]initWithImage:myImg];
    [myImgView setFrame:CGRectMake(10, 10, 100, 100)];
    [self.view addSubview:myImgView];

and then you implement the animation code to make the view larger

//START THE ANIMATION
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0];
    [myImgView setFrame:CGRectMake(10, 10, 300, 300)]; //re-set your image view size so that it become bigger
    [UIView commitAnimations];

or you can use the method animate (which is a little bit more advance, but better i think)

//START THE ANIMATION
    [UIView animateWithDuration:1.0 animations:^
    {
        [myImgView setFrame:CGRectMake(10, 10, 300, 300)]; //re-set your image view size so that it become bigger
    } completion:^(BOOL finished)
     {
         //type here what you want your program to do after the animation finished
     }];

good luck :D

Upvotes: 4

Related Questions