Search code examples
iosxcodezoomingscrollview

iOS: zooming an image with a button


I have an imageView as the background for the application. I have a button on top of the background. I want to press that button and have an animation of the background image being zoomed in. What is the best way to solve this problem? Should I use scrollview?


Solution

  • I think that using transform in an animation block is the best way. You can do something like this :

    [UIView animateWithDuration:0.3 animations:^
    {
        [yourImageView setTransform:CGAffineTransformMakeScale(1.5, 1.5)];
    }];
    

    and to place it back on the initial position you just need to do this :

    [UIView animateWithDuration:0.3 animations:^
    {
        [yourImageView setTransform:CGAffineTransformIdentity];
    }];