前言
前几天做项目遇到一个问题,一个之前同事用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;
}];
网友评论