我的屏幕上有一些动画。我正在使用精灵表通过 CAlayers 为所有这些设置动画。我正在下载所有大小为 4 MB 的资产viewDidAppear
。
我能够在模拟器和 iPhone 上显示动画。但在 iPad 上收到内存警告。
在我的设备崩溃报告中,它显示异常类型为
EXC_BAD_ACCESS(SIGSEGV)
我正在使用以下代码制作动画:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageNameStr]]; UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
CGImageRef richterImgPl1 = [UIImage imageWithContentsOfFile:getImagePath].CGImage;
NSArray *arrayWithSprites = [img spritesWithSpriteSheetImage:img
spriteSize:CGSizeMake(230,350)];
CGSize fixedSize = CGSizeMake(230, 350);
MCSpriteLayer *richterPl1 = [MCSpriteLayer layerWithImage:richterImgPl1 sampleSize:fixedSize] ;
richterPl1.frame = imgView.frame;
richterPl1.position = imgView.layer.position;
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"sampleIndex"];
anim.fromValue = [NSNumber numberWithInt:1];
anim.toValue = [NSNumber numberWithInt:arrayWithSprites.count];
anim.duration = sleepTime;//[imgView.animationImages count] * 0.0500;
anim.repeatCount = 1;
[richterPl1 addAnimation:anim forKey:nil];
[self.view.layer addSublayer:richterPl1];
摆脱这个问题的任何想法或线索?