首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将旧动画代码转换为新的iOS4块技术

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

Stack Overflow用户
提问于 2011-07-08 04:25:20
回答 1查看 863关注 0票数 1

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

书中所说的:

代码语言:javascript
复制
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationTimer];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDidStopSelector:@selector(lastAnimationZero)];

//animations

[UIView commitAnimations];

我的(显然是失败的)翻译:

代码语言:javascript
复制
[UIView animateWithDuration:animationTimer
                    options: (UIViewAnimationOptionAllowUserInteraction | 
                              UIViewAnimationOptionCurveEaseOut)
                 animations: ^
                 {
                     animation
                 }
                 completion:^(BOOL finished)
                 {
                     lastAnimation = 0;
                 }];

每次我运行它时,我(使用block方法)得到"Program received signal:"SIGABRT“,控制台显示

代码语言:javascript
复制
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+    
[UIView animateWithDuration:options:animations:completion:]: unrecognized selector sent to class 0x8393b4'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-08 04:31:26

检查文档中是否有UIVIew。没有这样的方法。你编写代码块语法的方式还可以,只要发送正确的消息即可。

另外,用你需要的指令替换‘lastAnimation = 0;’,这本书不会告诉你,以及旧版本中的[UIView setAnimationDidStopSelector: @selector(lastAnimationZero)];,实际上是动画停止时发送的消息,不应该直接翻译成lastAnimation = 0;

下面是您可能想要使用的方法文档的link

代码语言:javascript
复制
+(void)animateWithDuration:(NSTimeInterval)duration
                     delay:(NSTimeInterval)delay
                   options:(UIViewAnimationOptions)options
                animations:(void (^)(void))animations
                completion:(void (^)(BOOL finished))completion;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6616721

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档