iOS缩小动画

时间:2015-09-23 08:42:08

标签: ios animation imageview transform

当用户点击它时,我试图放大圆形轮廓图像视图,然后当他点击屏幕上的任何其他位置时,图像视图必须恢复到正常尺寸。两个方向的缩放都必须是动画的。

这是我用来放大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);
    }];

使其恢复正常规模的代码:

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

向上扩展工作正常,但缩小比例不是动画。它只是消失了。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:2)

尝试不设置图像视图的帧,只需像这样设置变换以扩展:

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

签约:

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

答案 1 :(得分:0)

在第二个动画中试试这个:

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