Kavita Kanwar
Kavita Kanwar

Reputation: 285

iOS scale down animation

I'm trying to enlarge a circular profile imageview when the user taps on it and then when he taps anywhere else on the screen, then the imageview has to come back to its normal size. Scaling in both the directions has to be animated.

This is the code that I'm using to enlarge the imageview:

    CGRect frame = CGRectMake(0, 0, 200, 200);
    imageView.frame = frame;
    imageView.transform = CGAffineTransformMakeScale(0, 0);
    [UIView animateWithDuration:0.5 animations:^{
        imageView.transform = CGAffineTransformMakeScale(1, 1);
    }];

Code to bring it back to normal size:

    CGRect frame = CGRectMake(0, 0, 50, 50);
    imageView.frame = frame;
    imageView.transform = CGAffineTransformMakeScale(1, 1);
    [UIView animateWithDuration:0.5 animations:^{
        imageView.transform = CGAffineTransformMakeScale(0, 0);
    }];

Scaling up is working fine but scaling down is not animated. It just disappears. Could anybody help?

Upvotes: 0

Views: 1436

Answers (2)

Cristiano Alves
Cristiano Alves

Reputation: 233

Try this in second animation:

CGRect frame = CGRectMake(0, 0, 50, 50);
self.imageView.frame = frame;
self.imageView.transform = CGAffineTransformMakeScale(4, 4);
[UIView animateWithDuration:0.5 animations:^{

        self.imageView.transform = .identity
}];

Upvotes: 0

Anand V
Anand V

Reputation: 423

Try without setting the frame for the image view and just setting the transform like this to expand:

[UIView animateWithDuration:0.5 animations:^{
        _settingsProfilePlaceholderImageView.transform = CGAffineTransformMakeScale(2, 2);
    }];

To contract:

[UIView animateWithDuration:0.5 animations:^{
        _settingsProfilePlaceholderImageView.transform = CGAffineTransformMakeScale(1, 1);
    }];

Upvotes: 2

Related Questions