I have an animation that I'm adding to a view. In the animation, I have a cell that collapses as if it's being folded. I split the view into two separate layers and apply a rotation on each layer. This is working, however, the effect is more subtle than I'd like. I'm looking for a way to increase the gap between the ends of the centerline (top and bottom edges of each layer) extends in during the animation. Basically, the halves aren't tall enough to convincingly look like they're folding backwards. Here is what I currently have mid animation, the orange lines are approximately where I would want the lines to fall during the animation:
Here is the code handling the rotation:
- (CABasicAnimation *)foldLayerToValue:(CGFloat)toValue expanding:(BOOL)expanding
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
CATransform3D rotate = CATransform3DIdentity;
rotate.m34 = 1.0 / -2000.f;
rotate = CATransform3DRotate(rotateAndScale, [self radiansFromDegrees:toValue], 1.f, 0.f, 0.f);
animation.toValue = [NSValue valueWithCATransform3D:rotateAndScale];
return animation;
}
This gets added to a CATransaction that also moves the lower section down the correct amount during the animation. I tried adding a scale factor to the animation, but that has an affect on the entire layer, scaling both the top and bottom edges. I tried increasing the height of the layers as they rotate, but that also provided unsavory results.
Any ideas? Is there any way I can manually set the position on a corner by corner basis?
I think part of the problem is that my anchor points are on the center line. During rotation, the top and bottom edges are getting closer to the POV, rather than the center line getting farther away. You can see that the corners are off the screen slightly which is limiting the amount that you can see the effect. I had previously had a version with the anchor points on the top and bottom of the layers, but I was unable to get the two layers to remain "touching" as the animation occurred. I had tried adding a translate to the Z coordinate during the animation, but it seemed to have no effect on anything.
The value you are using (-1.0/2000.0
) corresponds to an object being far away from the camera/eye and usually has a low perspective. If you want something that has more perspective then you should change it to something that corresponds to a smaller distance to the camera. Usually the range of circa 500-800 is a "normal" distance, so you are probably looking for something in the 200-400 range.
That is: change the .m34
value to -1.0/200.0
and there will be more perspective.