如何创建CAAnimation效果,例如月亮在IOS中绕地球旋转并同时自转呢? [英] How to create a CAAnimation effect like moon rotates around the earth and rotates by itself at the same time in IOS?

查看:171
本文介绍了如何创建CAAnimation效果,例如月亮在IOS中绕地球旋转并同时自转呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在IOS中创建使月亮绕地球旋转的效果很简单.假设月亮是CALayer对象,只需将其更改为地球锚定点,然后它将围绕地球旋转.但是如何创建同时旋转的月亮呢?由于月亮只能有一个anchorPoint,看来我无法再使这个CALayer对象自转了.你们有什么感想?谢谢.

I know it is simple to create the effect making the moon circling around the earth in IOS. Suppose the moon is a CALayer object, just change the anchorPoint of this object to the earth then it will animate circling around the earth. But how to create the moon that rotate by itself at the same time? since the moon can only have one anchorPoint, seems I can not make this CALayer object rotate by itself anymore. What do you guys think? thanks.

推荐答案

使用两层.

  • 一个是从地球到月球的看不见的手臂".它围绕其锚点(地球的中心)进行旋转变换.这会导致臂"末端的月亮绕地球旋转.

  • One is an invisible "arm" reaching from the earth to the moon. It does a rotation transform around its anchor point, which is the center of the earth. This causes the moon, out at the end of the "arm", to revolve around the earth.

另一个是月亮.它是手臂"的子层,位于手臂的末端.如果要使其独立旋转,请将其绕其自身的中心 锚点旋转.

The other is the moon. It is a sublayer of the "arm", sitting out at the end of the arm. If you want it to rotate independently, rotate it round its anchor point, which is its own center.

(但是,请注意,真实的月亮并不能做到这一点.对于真实的月亮,手臂"就足够了,因为真实的月亮与自己围绕地球的自转同步旋转-因此我们总是看到月亮的同一张脸.)

(Be aware, however, that the real moon does not do this. For the real moon, the "arm" is sufficient, because the real moon rotates in sync with its own revolution around the earth - so that we see always the same face of the moon.)

这篇关于如何创建CAAnimation效果,例如月亮在IOS中绕地球旋转并同时自转呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆