iOS高级动画CGAffine Transform

前言

前几天做项目遇到一个问题,一个之前同事用xib写的弹框,需要加一个缩放的动画效果,结果我用普通的改变frame的方法对其进行移动和缩放时,其内部的部分view没有随着父视图缩放,最后用CGAffine Transform解决该问题。

CGAffineTransformMakeTranslation

位移效果:有两个参数,分别是x、y坐标的偏移量

    [UIView animateWithDuration:1 animations:^{
        _testView.transform = CGAffineTransformMakeTranslation(100, 100);
    }];

CGAffineTransformMakeScale

等比缩放效果:两个参数,别是长、宽的缩放比例

    [UIView animateWithDuration:1 animations:^{
        _testView.transform = CGAffineTransformMakeScale(2.0f, 2.0f);
        _testView.transform = CGAffineTransformMakeScale(1.0, 1.0);
    }];

CGAffineTransformMakeRotation

旋转效果:一个参数,转的角度,用一个π的宏定义M_PI

    [UIView animateWithDuration:1.0f animations:^{
        CGAffineTransform transform1 = CGAffineTransformMakeRotation(M_PI_2);
        CGAffineTransform transform2 = CGAffineTransformScale(transform1, 0.5, 0.5);
        _testView.transform = CGAffineTransformTranslate(transform2, 100, 100);
    }];

CGAffineTransformConcat

组合动画:参数是两个CGAffineTransform,也就是说可以同时执行两个参数的动画效果

   [UIView animateWithDuration:0.5 animations:^{
                    weakPopLoginView.middleView.transform = CGAffineTransformConcat(CGAffineTransformMakeScale(0.01f, 0.01f), CGAffineTransformMakeTranslation(gifPoint.x - centerPoint.x, gifPoint.y - centerPoint.y));
                    weakPopLoginView.alpha = 0;
                }];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容