我想在视图加载几秒钟后显示一个动画图像,然后将其隐藏并查看其他 2 个图像,我使用了一个数组来为图像设置动画然后设置一个计时器来重复调用函数 onTimer,在这个函数中我检查是否图像动画一次,如果是这样,请停止计时器并查看其他 2 个图像
当我运行项目时它工作正常,只是在我点击屏幕之前不会出现 2 张图像!
她是代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
outline.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"traffic.png"],
[UIImage imageNamed:@"red.png"],
[UIImage imageNamed:@"yellow.png"],
[UIImage imageNamed:@"green.png"], nil];
[outline setAnimationRepeatCount:1];
outline.animationDuration = 4;
[outline startAnimating];
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0/30.0 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
}
-(void) onTimer {
if (![outline isAnimating] == TRUE){ // if animation has been played once, do something
NSLog(@"animation stopped, do something");
rannan.image = [UIImage imageNamed:@"rannan.png"];
outline.image = [UIImage imageNamed: @"outline.png"];
[ timer invalidate];
// do something
}
}
看起来由于某种原因 isAnimating 没有设置为 TRUE 直到我在项目运行时单击屏幕
希望我能找到这个答案:)