开发者

Proper use of finished: in setAnimationDidStopSelector:?

I have some playing cards that flip over when you tap them. I want some stuff to happen after the flip animation is complete, so I have this in my UIView animation cycle:

[UIView setAnimationDidStopSelector:@selector(f开发者_JS百科lipAnimationDone:finished:context:)];

...which calls this:

-(void)flipAnimationDone:(NSString *)animationID finished:(BOOL)finished context:(void *)context {
    if (finished == YES) {
        // other stuff here
    }
}

Now, I need the if (finished == YES) bit in there, because otherwise the other stuff will fire even if the user taps the card again mid-animation, which is bad -- it needs to only happen if the flip animation completes completely :)

Problem is, this isn't working. If I have the if in there, the other stuff doesn't ever fire, no matter what. If I leave the if out, the other stuff fires, but possibly at the wrong time.

What am I doing wrong with the finished bit that is making it not work properly?

Thanks!


Notice that the documentation says the method signature is

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;

Specifically,

finished
An NSNumber object containing a Boolean value. The value is YES if the animation ran to completion before it stopped or NO if it did not.

So, you should make it (NSNumber *)finished and if ([finished boolValue]) { ... }.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜