我尝试在AnimationGroup中的特定时间播放声音我怎么能这样做。
我应该使用NSTimer还是其他计时器?
for (int i = 0; i<[bildr count]; i++) {
...
CABasicAnimation *fadeInAnimation;
if([[[bildr objectAtIndex:i] objectForKey:@"animation"] isEqualToString:@"fadeIn"]) {
greenLeafImageView.alpha = 0.0;
fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
[fadeInAnimation setToValue:[NSNumber numberWithFloat:1.0]];
fadeInAnimation.fillMode = kCAFillModeForwards;
fadeInAnimation.removedOnCompletion = NO;
fadeInAnimation.duration = [[[bildr objectAtIndex:i] objectForKey:@"duration"] floatValue];
fadeInAnimation.beginTime = CACurrentMediaTime() + [[[bildr objectAtIndex:i] objectForKey:@"startTime"] floatValue];
}else{
// is sound -> time it
}
[animArray addObject:fadeInAnimation];
[greenLeafImageView.layer addAnimation:fadeInAnimation forKey:nil];
lastpic=i;
}
float totaltime=20.0;
CAAnimationGroup * group = [CAAnimationGroup animation];
group.animations = animArray;
group.duration = totaltime;
[self.view.layer addAnimation:group forKey:nil];
答案 0 :(得分:0)
简短回答,是的,NSTimer
是你必须走的路。
我写了一个用动画来协调声音的课程。您可以查看here on github。这个类MKSoundCoordinatedAnimationLayer
还允许您通过传递NSDictionary
相关图像,位置,字母,声音和计时信息来“编写”动画,这反过来允许您配置/将动画保存在运行时加载的plist中,而不是必须修改代码以调整动画。