I want to animate my CALayer to show up for a while, then fade out, here is my code
[_msgLayer removeAllAnimations];
[UIView animateWithDuration:10 delay:0 options:0 animations:^ {
_msgLayer.hidden = false;
NSLog(@"showing");
} completion:^(BOOL finished) {
NSLog(@"showing done, finished=%d", finished);
[UIView animateWithDuration:10 delay:40 options:0 animations:^ {
_msgLayer.hidden = true;
} completion:^(BOOL hideFinished) {
NSLog(@"hiding done, finished=%d", hideFinished);
}];
}];
However, the animation simply doesn't work as I expected, everything complete almost immediately
2014-10-26 10:11:28.249 Foobar[91761:6827358] showing
2014-10-26 10:11:28.254 Foobar[91761:6827358] showing done, finished=1
2014-10-26 10:11:28.255 Foobar[91761:6827358] hiding done, finished=1
I see some similar questions out there, some people say hidden
is not animatable, but the document says it's animatable. And I also tried opacity
, then same result, the animation still finish immediately. Why is that? and how can I solve that?
The _msgLayer
is my own class inherits CALayer and it has own drawing method. And this animation is called from networking event, like server send a message to iPhone, then I show the message on the screen.