小编cho*_*lot的帖子

IOS 5和RemoteIO的CABasicAnimation延迟问题

我正在为iPhone创作一种乐器.在我的应用程序中,当我触摸CALayer时,会弹奏一个音符,并且该音符会在音符持续时间内摆动.

这一切都在iOS 4.1上完美运行,但是我刚刚升级到iOS 5.0.1,并且如果我连续按下多个音符,则会遇到严重的滞后问题.在经历了很多痛苦之后,我将其缩小到以下针对触摸的CALayer的摆动动画代码.

// here is an example wiggle
CABasicAnimation *wiggle = [CABasicAnimation animationWithKeyPath:@"transform"];
wiggle.duration = 0.1;
//wiggle.repeatCount = 1e100f;
wiggle.repeatCount = 100;
wiggle.autoreverses = YES;
wiggle.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(fret.fretLayer.transform,0.2, 0.0 ,1.0 ,2.0)]; //angle, x , y , z
wiggle.fromValue = [NSValue valueWithCATransform3D:CATransform3DRotate(fret.fretLayer.transform,-0.2, 0.0 ,1.0 ,2.0)]; //angle, x , y , z

// doing the wiggle
[note.noteLayer addAnimation:wiggle forKey:@"wiggle"];
Run Code Online (Sandbox Code Playgroud)

如果我阻挡了动画添加到图层的最后一行,则所有延迟都会立即消失.这感觉就像在主线程被阻塞不知何故,或者它不是在主线程上运行,但我试图调用与performSelectorOnMainThread功能:withObject:waitUntilDone:NO,它并没有区别.如果我非常快速地按下大量的音符,整个应用程序会暂停,然后大约一秒钟之后,就像它会自动赶上并突然播放所有声音,动画最终开始变得不稳定并且在此之后窒息.

有谁知道iOS 5中CABasicAnimation的任何异常问题?是否有任何其他可以尝试的动画API,可以在重复时为CALayers设置一个未指定的持续时间?任何人都有任何建议或猜测如何解决/问题可能源于什么?

编辑:我已经确定它绝对与动画的本质无关.我用简单地淡化颜色的代码替换了摆动代码,但是我仍然得到相同的滞后效果,因为音符有些滞后.

CABasicAnimation *wiggle = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
wiggle.duration = 2;
wiggle.toValue = (id)[UIColor whiteColor].CGColor ;
wiggle.fromValue = (id)[UIColor …
Run Code Online (Sandbox Code Playgroud)

iphone core-animation core-audio audiounit ios

5
推荐指数
1
解决办法
977
查看次数

标签 统计

audiounit ×1

core-animation ×1

core-audio ×1

ios ×1

iphone ×1