views:

128

answers:

1

Hello, I have this View class. It adds subviews to itself and then I want to do a CATransform3DMakeRotation on one of them (the last one added with addSubiew). Its on top but as soon as the animation starts it is underneath the oder views. Here is my CATransform3DMakeRotation code:

    CABasicAnimation *topAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
topAnim.duration=3.3;
topAnim.repeatCount=0;
topAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0, 0, 0, 0)];
float f = DegreesToRadians(180);  // -M_PI/1;
topAnim.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(f, 1,1, 0)];
//topAnim.delegate = self;
topAnim.removedOnCompletion =NO;
topAnim.fillMode = kCAFillModeForwards;
[[KuvertLasche layer] addAnimation:topAnim forKey:@"flippy"];

What am I doing wrong? Edit: This view is in a subview with a bunch of other views:

  • self.view
  • letterView (with 3 subviews. ontop of them is the KuvertLasche)

if i take it out of the letterView and place it on self.view above the letterView it goes half way and then goes under the other views. Very strange. Any advice?

+1  A: 

If I understand you correctly, when you start the animation parts of your view are disappearing under other views. This is happening because the rotation you are applying is occurring in 3-D about a diagonal line midway between the X and Y axes. As your view flips in 3-D, part of it will be physically lower than the other views.

To prevent this, you can change the position in Z of the other views by setting their layer's zPosition property to a large enough positive value, or by setting this view's layer's zPosition to a large negative (unless I have my signs mistaken for Core Animation Z ordering).

An example of this for your view's layer would be

KuvertLasche.layer.zPosition = -30.0f;
Brad Larson
Thank you so much! This is was i was searching for!
david
btw. I did a KuvertLasche.layer.zPosition = 300.0f;
david