-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Tweenable CGAffineTransform & CATransform3D #9
Conversation
Use theses types as Tweenable, for instance allows you to easily interpolate from a linear transformation matrix to the identity matrix.
I definitely think that conformance for CGAffineTransform and CATransform3D should be included out of the box. I haven't done too much work with matrices, but I assume that strange animations can occur because there is more than one way in which a matrix can describe certain positions? So in that case the route between to transforms can be mathematically correct, but not what the user might expect? |
I had a closer look to this subject. The linear interpolation that I was using only gave good looking results on scaling and translation transforms. This is because they are affine transforms. The idea is to build a component that derives scaling, translation, rotation axis and rotation angle from a basic transform. Then we can tween on the component's variables. Here the components will be How we use it :
We could also keep CGAffinetransform and CATransform3D Tweenable and use under the hood these components. But this implies that we have to derived translation, scaling and rotation parameters on every frame which is rather expensive. This would look like :
|
Thanks for putting so much work in to this, the example looks awesome! I get how you're using the nested Can you explain a little about what happens when you initialise one of those from a UIKit transform, for instance I get a little lost at that point, and I'm not sure how the Also, when you say 'If provided transform doesn't result from a translation, a scaling and a rotation, the resulting matrix is undetermined', can you clarify what that means? |
Hey @SteveBarnegren ! Sorry for this long unavailable period. When initializing a Transform3D, what it does is :
Lastly, the input matrix can be any other transformation that is not a combination of translation, scaling and rotation. In that case it will return a transform with the current extracted translation and scaling which is not a close match of the input. The tweening won't be continuous here. We can either use a failable init when the transform is not a combination of translation, scaling and rotation. |
CGAffineTransform and CATransform3D should be Tweenable.
It may produce strange animation for complex transformations, but for simple ones as animating a translation, a scaling or a rotation it is great.
Example :