在我的应用程序中,我需要设置一个动画,它将重复运行,直到我对它执行操作。我希望图像和文本沿着变化。我现在尝试建议的关键帧动画,但它只显示最后的变化,没有重复。我做了一些搜索,并查看了文档,但我肯定仍然错过了一些东西。
我的理解是animateKeyframesWithDuration
以秒为单位,而相对开始和相对持续时间的值为0 - 1,因此我将每个值设置为0.2,因为有5个,0.2正好是五分之一。我做错了什么?所有NSLog都会触发,但除了最后一个事件外,没有任何事件发生实际更改。
[UIView animateKeyframesWithDuration:70 delay:0 options:UIViewKeyframeAnimationOptionRepeat animations:^{
[UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.2 animations:^{
NSLog(@"a1");
self.eventsText.text = nil;
theImageView.image = [UIImage imageNamed:@"welcome.png"];
}];
[UIView addKeyframeWithRelativeStartTime:0.2 relativeDuration:0.2 animations:^{
NSLog(@"a12");
theImageView.image = [UIImage imageNamed:@"pleasepray.png"];
self.eventsText.text = @"Test2";
}];
[UIView addKeyframeWithRelativeStartTime:0.4 relativeDuration:0.2 animations:^{
NSLog(@"a13");
theImageView.image = [UIImage imageNamed:@"comingevents.png"];
self.eventsText.text = @"Test3";
}];
[UIView addKeyframeWithRelativeStartTime:0.6 relativeDuration:0.2 animations:^{
NSLog(@"a14");
theImageView.image = [UIImage imageNamed:@"birthdays.png"];
self.eventsText.text = nil;
}];
[UIView addKeyframeWithRelativeStartTime:0.8 relativeDuration:0.2 animations:^{
NSLog(@"a14");
theImageView.image = [UIImage imageNamed:@"ournumbers.png"];
self.eventsText.text = @"Test4";
}];
} completion:nil];
1条答案
按热度按时间nx7onnlm1#
好的,这就是我最后做的。我只有5个不同的“幻灯片”需要旋转,其中一些没有文本。现在,我把文本放入一个数组中来模拟我需要的内容。将来,这将是动态的,从服务器中提取。然后,我设置了一个NSInteger属性来链接所有内容。并从这个数组中提取,以沿着每个图像动画所需的时间。