Search code examples
iphoneioscore-animationcabasicanimationquartz-core

CALayer deepness


So, easilly I have UIButton and the title of my bytton is - "title" ;)

I want simply animate titleLabel of UIButton with steps:

1) Animate label by Y to M_PI/2. (Kind of "flip" animation but half)

2) Replace "Title" of button with "NewTitle"

3) Animate label by Y back.

enter image description here

So I have:

CABasicAnimation* flipAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
flipAnimation.toValue = [NSNumber numberWithFloat: M_PI/2];
flipAnimation.duration = 3;
flipAnimation.delegate = self;
[self.testButton.titleLabel.layer addAnimation:flipAnimation forKey:@"flip"];

While animating, the half of text is invisible. I understand why it happens, but can't manage how to avoid it.

Thansk, for your help.

enter image description here


Solution

  • Try setting the z value of the transform to a (negative?) value of about 1/2 the label's width before beginning the animation That should lift the label above the button so that half of it doesn't disappear behind the button as it rotates around it's Y axis.

    Edit: Actually, it might be better to set the zPosition property of the layer. That should shift the layer above the other layers without affecting it's apparent size.