[英]How to create and delay an animation in objective-c?
我有一个5x5的跳棋板自定义UIView
,它填充了我单击为黑色的框。 我想创建一个动画,程序在程序中会按顺序记住我的点击,然后按一下按钮,它会按照我执行的顺序进行动画处理并将框填充为黑色。 如何在每次过渡之间有2秒的间隔创建这种动画?
谢谢你的帮助。
您可以使用NSTimer等待2秒,然后浏览您定义的动画数组。
因此,首先您需要存储您的点击顺序
NSMutableArray * clicks = [[NSMutableArray alloc] init];
在您的“ .h”中声明一个int计数器: int cont
,并将其设置为0。
然后,当您想开始制作动画时,请初始化NSTimer:
NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(fillAnotherSquare:) userInfo:nil repeats:YES];
最后,您的方法“ fillAnotherSquare”
-(void) fillAnotherSquare: (id ) sender{
if (cont == squareNumbers)
[timer invalidate];
/* Fill the square with index "cont" */
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.