Iphone 将旧动画代码转换为新的iOS4块技术

Iphone 将旧动画代码转换为新的iOS4块技术,iphone,objective-c,cocoa-touch,core-animation,objective-c-blocks,Iphone,Objective C,Cocoa Touch,Core Animation,Objective C Blocks,我正试图通过一本2009年的书来学习动画,据我所知,在iOS4中制作动画的首选方法是使用块。我正在读的这本书使用了旧方法,我一直在尝试将其转换为新方法,但收效甚微 书中说: [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:animationTimer]; [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; [UIView setAnimatio

我正试图通过一本2009年的书来学习动画,据我所知,在iOS4中制作动画的首选方法是使用块。我正在读的这本书使用了旧方法,我一直在尝试将其转换为新方法,但收效甚微

书中说:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationTimer];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDidStopSelector:@selector(lastAnimationZero)];

//animations

[UIView commitAnimations];
我(显然失败)的翻译:

[UIView animateWithDuration:animationTimer
                    options: (UIViewAnimationOptionAllowUserInteraction | 
                              UIViewAnimationOptionCurveEaseOut)
                 animations: ^
                 {
                     animation
                 }
                 completion:^(BOOL finished)
                 {
                     lastAnimation = 0;
                 }];
每次我运行它时,我(使用block方法)都会得到“程序接收信号:”SIGABRT“,控制台会显示

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+    
[UIView animateWithDuration:options:animations:completion:]: unrecognized selector sent to class 0x8393b4'
检查文档是否存在错误。没有此类方法。 您编写块语法的方式还可以,只需发送正确的消息即可

另外,将“动画”替换为您需要的说明,本书不会告诉您,以及
[UIView setAnimationDidStopSelector:
@选择器(lastAnimationZero);
在旧版本中,实际上是动画停止时发送的消息,不应直接转换为
lastAnimation=0;

下面是您可能想要使用的方法文档的一个示例

+(void)animateWithDuration:(NSTimeInterval)duration
                     delay:(NSTimeInterval)delay
                   options:(UIViewAnimationOptions)options
                animations:(void (^)(void))animations
                completion:(void (^)(BOOL finished))completion;

我添加了lastAnimationZero部分,它所做的一切实际上就是将lastAnimation设置为零,这就是它的本意。我也已经有了动画,只是不想占用空间。现在不幸的是,即使在我清理了我的块语法(清理了完成部分)之后它仍然给了我同样的错误。我只是不明白。我需要做什么特殊的事情来启用块语法吗?导入头文件和框架吗?没有要包含的头或框架,块语法会出现ios4。尝试阅读一些关于块的内容。正如我所说的,出现异常是因为在
UIView
中没有定义此类方法我真傻。出于某种原因,我认为我可以排除以下任何一个块,所以我跳过了延迟,因为我不需要它。我只是简单地把延迟:0.0,它就像一个符咒。非常感谢。