AnimationDidStop 没有被调用

Posted

技术标签:

【中文标题】AnimationDidStop 没有被调用【英文标题】:AnimationDidStop not being called 【发布时间】:2012-04-02 15:11:24 【问题描述】:

由于某种原因没有调用我的 animationDidStop 方法,最初我认为这是因为未设置委托,但经过补救后我仍然遇到同样的问题。有任何想法吗?在此先感谢:)

- (void)hideInterfaceButtonClicked : (id) sender


[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop)];

[UIView beginAnimations:@"MoveView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.5];

// Move to the right
CGAffineTransform translateInterface = CGAffineTransformMakeTranslation(454,288);
// Scale
CGAffineTransform scale = CGAffineTransformMakeScale(0.20,0.20);   

// Apply them to the view
self.transform = CGAffineTransformConcat(scale, translateInterface);

self.alpha = 0.0;

[UIView commitAnimations];



- (void)animationDidStop 

NSLog(@"Animation Has Stopped");
[[NSNotificationCenter defaultCenter] postNotificationName:@"hiddenInteraceViewNeeded" object:self]; //after MoveView finishes


【问题讨论】:

尝试移动 setAnimationDelegatesetAnimationDidStopSelector beginAnimations... 【参考方案1】:

你可以通过the new (ios4+) block syntax实现你想要的:

[UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationCurveEaseIn
                 animations:^
                     // Move to the right
                     CGAffineTransform translateInterface = CGAffineTransformMakeTranslation(454,288);
                     // Scale
                     CGAffineTransform scale = CGAffineTransformMakeScale(0.20,0.20);   

                     // Apply them to the view
                     self.transform = CGAffineTransformConcat(scale, translateInterface);

                     self.alpha = 0.0;
                  completion:^(BOOL finished) 
                     NSLog(@"Animation Has Stopped");
                     [[NSNotificationCenter defaultCenter] postNotificationName:@"hiddenInteraceViewNeeded" object:self]; //after MoveView finishes
                 ];

【讨论】:

Cheers 效果很好,我已经推迟使用更新的符号一段时间了。

以上是关于AnimationDidStop 没有被调用的主要内容,如果未能解决你的问题,请参考以下文章

CABasicAnimation - 未调用 animationDidStop

立即调用 animationDidStop 方法

animationDidStop:finished: 未调用

核心动画 - 未调用 animationDidStop

iOS - [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)] 调用太快了

未使用 NSAnimationContext 调用 CAAnimation animationDidStop