我试图加载4个UIImageView来运行不同的动画。每个动画由164 png的6 KB大小组成。
我已在仪器中测试过,在模拟器中运行时工作正常,内存大小小于5.5 MB。
但是当在iPad上运行时,应用程序崩溃而没有日志消息或内存警告。我已经在仪器中进行了测试,并且在崩溃之前内存中的大小小于5 MB。
这里的代码。
-(void)startAnimations
{
OTAnimationProvider *ani = [[OTAnimationProvider alloc] init];
int a;
for (a=0;a<[teams CountY];a++)
{
UIImageView *animationTeam = [[UIImageView alloc] initWithFrame:CGRectMake(10, 300 + (40 * a), 1004, 300)];
int idTeam = [[teams getValueByName:@"IdTeam" posY:a] intValue];
[animationTeam setAnimationImages:[ani animationWithName:[NSString stringWithFormat: @"OTScoreBoardLeague_%d_%d_",idTeam,a+1] frameCount:164 step:2]];
[animationTeam setAnimationDuration:animationPlayersTime];
[animationTeam setAnimationRepeatCount:1];
[animationTeam startAnimating];
[self.view addSubview:animationTeam];
[animationTeam release];
}
[ani release];
}
OTAnimationProvider对象只是一个具有返回动画的图像数组的方法的对象。
知道我做错了什么:(
感谢。
UPDATE ---
我试图使用带有CALayer对象的动画Atlas。但我仍然可以获得相同的结果。
在设备中,应用程序在调试时崩溃而没有任何错误消息。
这是代码:
CALayer *layer = [CALayer layer];
CGImageRef img = [[UIImage imageNamed:@"OTScoreBoardLeagueAtlasTeam_1_1.png"]CGImage];
layer.contents = (id)img;
CGSize size = CGSizeMake( 1004, 300 ); // size in pixels of one frame
CGSize normalizedSize = CGSizeMake( size.width/CGImageGetWidth(img), size.height/CGImageGetHeight(img) );
layer.bounds = CGRectMake( 0, 0, size.width, size.height );
layer.contentsRect = CGRectMake( 10, 300 + (20 * a), normalizedSize.width, normalizedSize.height );
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"sampleIndex"];
anim.fromValue = [NSNumber numberWithInt:1]; // initial frame
anim.toValue = [NSNumber numberWithInt:165]; // last frame + 1
anim.duration = 8.0f; // from the first frame to the 6th one in 1 second
anim.repeatCount = 0; // just keep repeating it
anim.autoreverses = NO; // do 1, 2, 3, 4, 5, 4, 3, 2
[layer addAnimation:anim forKey:nil]; // start
[self.view.layer addSublayer:layer];
有什么想法吗?
感谢。