views:

357

answers:

1

Hey guys.

I recently posted my problem but neither did I get an answer here or elsewhere, nor can I find my post again... Anyways, I want to try to state my point clearer, hoping you can help me this time maybe.

The part of code, this is about, looks like this:

CABasicAnimation *animation = nil; 
CATransform3D transform;

animation = [CABasicAnimation animationWithKeyPath:@"transform"];

transform = CATransform3DMakeRotation(1.57f, 0.0f, 1.0f, 0.0f); 
value = [NSValue valueWithCATransform3D:transform]; 
[animation setToValue:value];
[animation setAutoreverses:YES]; 
[animation setDuration:0.5f];
[[shieldView layer] addAnimation:animation forKey:@"180"];

What happens, is that I have a UIImageView with an image in it. I take this View and rotate it around the z-Axis for half a turn (1.57 measured in arc).

Now there is another View overlapping with the one being transformed in 3d. This leads to my problem: As soon as the transformation is executed, the transformed layer is sort of clipped against the overlapping view, but wrong, so that u see a 'flickering' effect to both Views.

Now I dont know, why this happens. I would expect the view to be animated appropriatly, without this 'bug', and the Views to be just displayed correctly.... since I do not do anything special.

I have tried to overlay 2D transformations, using the 'beginAnimations' and 'commitAnimations' context, which works fine. This means, the problem is sort of hidden in the 3D rotation of my View.

You guys have any clues on this? I hope I explained that well enough.

+2  A: 

If these are two sibling views (subviews of the same superview), their layers can overlap, potentially creating the visual artifacts you see. You should be able to either reposition the views relative to one another in the view hierarchy (make one view a level above or below the other) or directly set the Z position of the view's layer. If you do something like

shieldView.layer.zPosition = 1.0f;

your shieldView's layer should be slightly above the other view's layer (unless I'm remembering the coordinate space wrong and it needs to be -1.0f) and you should be able to avoid the clipping you see now.

Brad Larson
This worked like a charm, thanks a lot. Now I've noticed some specific behaviour, logical after all, namely that placing an image right behind the rotating one in the middle, makes you place the layer very far to the back! This has to be this way, ofc, since if my image rotates, as soon as its half way, it sort of reaches max. range into the frame and towards you. Just sth. I wanted to share.Is there any specific boundary to the z-Position?
Icky
Ok, so the distance seems to be measured in Pixel :)
Icky
I'm not sure what you're describing, but zPosition is a property that is implicitly animated on CALayer, so it will animate to the new zPosition by default. To disable this, you can wrap your call to that property in a CATransaction (begin / end), and call '[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];' before the change in setting. As far as the viewable range on zPosition, you'll need to check that yourself. I've seen differences on various OS versions and platforms.
Brad Larson