From CATransform3D to CGAffineTransform

I use the following function to apply an impulse effect to a view

- (void)pulse {

    CATransform3D trasform = CATransform3DScale(self.layer.transform, 1.15, 1.15, 1);
    trasform = CATransform3DRotate(trasform, angle, 0, 0, 0);

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
    animation.toValue = [NSValue valueWithCATransform3D:trasform];
    animation.autoreverses = YES;
    animation.duration = 0.3;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.repeatCount = 2;
    [self.layer addAnimation:animation forKey:@"pulseAnimation"];

}

I would like to get the same result using CGAffineTransform self.transform, not CATransform3D self.layer.transform. Is it possible?

+5
source share
3 answers

Converting a CATransform3Dto is possible CGAffineTransform, but you will lose some of the possibilities. I found it useful to convert the aggregate transformation of the layer and its ancestors to CGAffineTransformso that I can display it using Core Graphics. Limitations:

  • Your entry will be considered flat in the XY plane
  • Your conclusion will be considered flat in the XY plane.
  • / .m34

:

    // m13, m23, m33, m43 are not important since the destination is a flat XY plane.
    // m31, m32 are not important since they would multiply with z = 0.
    // m34 is zeroed here, so that neutralizes foreshortening. We can't avoid that.
    // m44 is implicitly 1 as CGAffineTransform m33.
    CATransform3D fullTransform = <your 3D transform>
    CGAffineTransform affine = CGAffineTransformMake(fullTransform.m11, fullTransform.m12, fullTransform.m21, fullTransform.m22, fullTransform.m41, fullTransform.m42);

3D-, , , , , CATransform3D CGAffineTransform. , , , 3D- . . , .

3D- Core Graphics, , ( !), , ,

    CGContextSaveGState(context);
    CGContextConcatCTM(context, affine);
    [layer renderInContext:context];
    CGContextRestoreGState(context);
+7

. CGAffineTransform Xcode, "CGAffineTransform Reference". "". , CATransform3DScale (CGAffineTransformScale) CATransform3DRotate (CGAffineTransformRotate).

, CATransform3DRotate . , 0 . CATransform3DRotate (trasform, angle, 0, 0, 1.0) Z. :

, undefined.

+2

func CATransform3DGetAffineTransform (_t: CATransform3D) → CGAffineTransform

0

All Articles