2011-04-17 32 views
0

我用在IBAction为(按下按钮)方法的代码:只有在UIButton动画完成后才更新标签?

CABasicAnimation *rotateButton; //don't forget to release 
rotateButton = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
rotateButton.fromValue = [NSNumber numberWithFloat:0]; 
rotateButton.toValue = [NSNumber numberWithFloat:((720*M_PI)/180)]; 
rotateButton.duration = 0.75; 
rotateButton.repeatCount = 1; 
[sender addAnimation:rotateButton forKey:@"720"]; 

,并有我想只更新后,这是完整的一个标签。我想知道是否有一个简单的例子,任何人都可以提供给我,让标签只在完成时更新,而不是在方法完成时更新。我知道你不能使用“@selector(animationDidStop:finished:context :)”,因为苹果不喜欢它。任何人的帮助?谢谢,麻烦您了!

回答

1

为什么不直接使用UIView动画块?

[UIView animateWithDuration:0.75 delay:0 options:0 animations:^{ 
    theButton.transform = CGAffineTransformMakeRotation((720*M_PI)/180); 
} completion:^{ 
    theLabel.text = @"Whatever"; 
}]; 

如果您需要4.x的预兼容性,使用旧的形式,UIView类方法+setAnimationDidStopSelector:,像这样:

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDidStopSelector:@selector(someMethodInWhichYouSetTheLabelText)]; 
    theButton.transform = CGAffineTransformMakeRotation((720*M_PI)/180); 
[UIView commitAnimations]; 
+0

我去了底部的代码,因为我希望它是4倍前。不幸的是,我对此感到陌生,并且在CGAffineTransformMakeRotation行中出现错误:“请求成员”转换为“不是结构或联合的东西”....对于像我这样的白痴有什么想法? – BFBC 2011-04-17 00:30:23

+0

Scratch ....我拼写错误... – BFBC 2011-04-17 03:33:17

+0

btw ..我唯一可以让@selector工作在多个按钮上并正确使用setAnimationDidStop @选择器的方法是使用[UIView setAnimationDelegate:self]行[UIView commit动画] – BFBC 2011-04-17 05:16:35

0

I know you cannot use "@selector(animationDidStop:finished:context:)"

其实你可以,只要给它另所以它不会与Apple内部方法冲突

关于你的问题:

CAAnimation Class Reference

delegate

Specifies the receiver’s delegate object.

animationDidStop:finished:

Called when the animation completes its active duration or is removed from the object it is attached to.

+0

另一个教训。谢谢。 – BFBC 2011-04-17 00:31:58

相关问题