Iphone 问题-播放声音时,动画冻结\变慢

Iphone 问题-播放声音时,动画冻结\变慢,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,播放声音时,动画冻结\变慢问题 声音大小20kb mp3 动画大小5kb png 在其他动画函数中也会发生这种情况 基本上,每当我播放一个声音,动画就会变慢或暂停,该怎么办 代码: 请尝试以下方法: [soundPink performSelector:@selector(play) withObject:nil afterDelay:0.001]; 声音文件有多大?有可能你试图在内存中加载过大的声音,这会减慢速度。记住,iPhone不是台式电脑,所以你必须更仔细地考虑媒体文件的大小。 答案可

播放声音时,动画冻结\变慢问题

声音大小20kb mp3

动画大小5kb png

在其他动画函数中也会发生这种情况

基本上,每当我播放一个声音,动画就会变慢或暂停,该怎么办

代码:


请尝试以下方法:

[soundPink performSelector:@selector(play) withObject:nil afterDelay:0.001];

声音文件有多大?有可能你试图在内存中加载过大的声音,这会减慢速度。记住,iPhone不是台式电脑,所以你必须更仔细地考虑媒体文件的大小。

答案可能是在动画块之前添加一个PraseReToAlay(可以显式播放),这样就不会有口吃了。

- (void) startAnimation {   
    [soundPink prepareToPlay];           
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.8];
    CGPoint destination = CGPointMake(152,20);
    pink.center = destination;
    [UIView commitAnimations];
    [soundPink play];           
}

AVAudioPlayer已经是异步的,这可能没有帮助,我发现播放前的大多数音频暂停都是在PrepareToplayer阶段,您可以手动调用该阶段。但是动画不会暂停音频。我发布了我的init函数(可能有问题)最大的是400kb,是不是太大了?
- (void) startAnimation {   
    [soundPink prepareToPlay];           
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.8];
    CGPoint destination = CGPointMake(152,20);
    pink.center = destination;
    [UIView commitAnimations];
    [soundPink play];           
}