ios - 如何使用多个变换为 CATransform3D 制作动画?

标签 ios core-animation core-graphics uiviewanimation

基本上,我围绕一个点旋转图层:

CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0 / -500;
transform = CATransform3DTranslate(transform, rotationPoint.x-center.x, rotationPoint.y-center.y, 0.0);
transform = CATransform3DRotate(transform, (rotationAngleFor) * M_PI / 180.0f, 0.0, 1.0, 0);
transform = CATransform3DTranslate(transform, center.x-rotationPoint.x, center.y-rotationPoint.y, 0.0);

我还创建了一个图层,将其添加到更大的图层,然后对其应用变换:

[self.layer addSublayer:myLayer];
myLayer.transform = transform;

如何制作动画?

注意-将它放在UIView 动画 block 中是行不通的。

最佳答案

编辑正如@DuncanC 所指出的,我的描述与实际代码不符。

您可以使用添加到图层的 CABasicAnimation,如下所示。

CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath: @"transform"];

    <here goes your definition of transform>

transformAnimation.toValue = [NSValue valueWithCATransform3D:newTransform];
transformAnimation.duration = 10;
[self.layer addAnimation:transformAnimation forKey:@"transform"];

这个动画执行层的transform属性从层的transform属性的原始值到newTransform的连续变化> 转型。更改需要 10 秒。

关于ios - 如何使用多个变换为 CATransform3D 制作动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12324270/

相关文章:

iphone - 如何声明必须在后台运行的 iPhone 应用程序?

ios - 自定义具有性能问题的 UINavigationController 推送/弹出动画

ios - 如何在 CPU 上同时运行 Core Animation 和 Core Image?

ios - 在 Swift 4 中移动 UIBezierPath 笔划的最佳方式是什么?

ios - 如何在 UIKit 中实现 Photoshop 曲线编辑器

ios - 将整数值从一个 ViewController 传递到另一个 ViewController 并将其显示在 UITextField 中

ios - iPhone SDK : does anybody know how to resize uiimage on scrolling

iphone - 在 4.0.0 上安装 iOS 4.0.2 SDK

iphone - CABasicAnimation 对drawInContext 的调用导致实例变量重置为零

swift - 2 UIBezierPath的绘制差异