Reputation:
I have an UIImageView i want to float off into the background. It should be shirking as it moves along the z-axis and converge towards the center as you'd image something moving away from you does.
I tried this piece of code
theImageView.layer.transform = CATransform3DTranslate(theImageView.layer.transform,1,1,
-100);
And this
theImageView.layer.transform = CATransform3DTranslate(theImageView.layer.transform,0, 0,
-300);
But the image is in the exact same place. Is it not possible to this kind of thing in core graphics?
How are people handling this if its not possible through CATransform? Using some kind of hack with scaling instead?
Many Thanks -Code
Upvotes: 1
Views: 2021
Reputation: 135558
Even though Core Animation works in 3D space, it does not use perspective by default. To create a perspective transform, you have to modify a member of the transformation matrix directly:
CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0 / -2000; // this value affects the "amount" of perspective
(see e.g. http://watchingapple.com/2008/04/core-animation-3d-perspective/).
Upvotes: 2
Reputation: 2992
Instead of using a UIImageView, just use a new CALayer you add as a sublayer to your current view layer. Set the contents property of the CALayer to a CGImageref of your UIImage.
Here is the Core animation layer documentation, its a very powerful way to use core graphics.
Also check providing layer content in the above link.
Upvotes: 0