gpt4 book ai didi

ios - CAAnimationGroup在动画开始时播放声音

转载 作者:行者123 更新时间:2023-12-03 02:14:35 26 4
gpt4 key购买 nike

我试图在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];

最佳答案

简短的答案,是的,NSTimer是您必须采用的路径。

我写了一个类来协调声音和动画。您可以查看here on github。此类MKSoundCoordinatedAnimationLayer,还允许您通过传递NSDictionary以及相关的图像,位置,alpha,声音和定时信息来“编写”动画,从而允许您将动画配置/保存在自己的plist中在运行时加载,而不必修改代码来调整动画。

关于ios - CAAnimationGroup在动画开始时播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20884557/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com