3

我知道这个问题被问了很多,但我已经尝试了所有其他答案,但我无法弄清楚为什么动画停止选择器没有被调用。这是代码:

-(void) moveImage:(UIImageView *)image duration:(NSTimeInterval)duration curve:(int)curve  x:(CGFloat)x y:(CGFloat)y annKey:(NSString *) annKey{  

[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
image.transform = transform;
[UIView beginAnimations:annKey context:NULL];
[UIView commitAnimations];

}

这是发送所有正确参数的主要动画函数。

- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{
if ([animationID isEqualToString:@"Burn"])
{
    NSLog(@"Animation: %@ has finished.",animationID);
}

NSLog(@"This does not get called, why not?");
}

我的 NSLog 都没有显示文本。我究竟做错了什么?

4

2 回答 2

8

你需要这样做——

[UIView beginAnimations:annKey context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];

// Now define rest.
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
image.transform = transform;

[UIView commitAnimations];
于 2012-07-03T16:51:42.243 回答
3

不知道问题是什么,但你真的不应该使用 beginAnimations/commitAnimations。相反,使用块动画。您直接在调用的完成部分定义完成代码。

[UIView animateWithDuration:2.0
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     // animation code
                 } 
                 completion:^(BOOL finished){
                     // completion code
                 }];
于 2012-07-03T16:53:45.313 回答