iOS的视图变换动画(iOS view transform animation)

2019-07-04 15:25发布

我可能失去了一些东西简单,但试图做一个简单的“Ken Burns效果”与图像视图。

首先,代码:

[UIView animateWithDuration:20
                      delay:2
                    options:UIViewAnimationCurveLinear
                 animations:^{
                   CGAffineTransform move = CGAffineTransformMakeTranslation(40, 40);
                   CGAffineTransform zoom    = CGAffineTransformMakeScale(1.2, 1.2);
                   CGAffineTransform transform = CGAffineTransformConcat(zoom, move);
                   self.imageView.transform = transform;
                 }
                 completion:^(BOOL finished){
                   NSLog(@"Done");
                 }];

我预计开始与在正常规模的图像视图,并将其扩展到尺寸的120%,比20秒。 而实际上,它开始时立即比正常尺寸,然后扩展到正常大小。

如果我使用分度值的倒数,它开始了放大,然后缩小到正常规模这是我想要的效果相反。

有任何想法吗?

Answer 1:

好吧,其实这工作,我想要做什么。

CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
transformAnimation.duration = 20.0;
transformAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
transformAnimation.removedOnCompletion = NO;
transformAnimation.fillMode = kCAFillModeForwards;

CATransform3D xform = CATransform3DIdentity;
xform = CATransform3DScale(xform, 1.2, 1.2, 1.0);
xform = CATransform3DTranslate(xform, 60, -60, 0);
transformAnimation.toValue = [NSValue valueWithCATransform3D:xform];
[self.imageView.layer addAnimation:transformAnimation forKey:@"transformAnimation"];


Answer 2:

这听起来像视图正在响应于所述改变重新布置通过它的父视图变换,套管它被缩小到的最终结果,一旦变换在动画块中设置变换。 关键是,你的第一次尝试进行更改直接向视图,而第二种方法与层工作。



Answer 3:

你有没有尝试启动形式当前变换你的ImageView的吗?

[UIView animateWithDuration:20
                      delay:2
                    options:UIViewAnimationCurveLinear
                 animations:^{
                   CGAffineTransform trans = self.imageView.transform;
                   CGAffineTransformTranslate(trans, 40, 40);
                   CGAffineTransformScale(trans, 1.2, 1.2);
                   self.imageView.transform = trans;
                 }
                 completion:^(BOOL finished){
                   NSLog(@"Done");
                 }];


文章来源: iOS view transform animation