我想知道这个动画代码的另一种选择..
-(void)movetree{
//[tree1 release];
treeMove = YES;
tree1.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"moving trees1.png"],
[UIImage imageNamed:@"moving trees2.png"],
[UIImage imageNamed:@"moving trees3.png"],
[UIImage imageNamed:@"moving trees4.png"],
[UIImage imageNamed:@"moving trees5.png"],
[UIImage imageNamed:@"moving trees6.png"],
[UIImage imageNamed:@"moving trees7.png"],
[UIImage imageNamed:@"moving trees8.png"],
[UIImage imageNamed:@"moving trees9.png"],
[UIImage imageNamed:@"moving trees10.png"],
[UIImage imageNamed:@"moving trees11.png"],
[UIImage imageNamed:@"moving trees12.png"],
[UIImage imageNamed:@"moving trees13.png"],
[UIImage imageNamed:@"moving trees14.png"],
[UIImage imageNamed:@"moving trees15.png"],
[UIImage imageNamed:@"moving trees16.png"],
[UIImage imageNamed:@"moving trees17.png"],
[UIImage imageNamed:@"moving trees18.png"],
[UIImage imageNamed:@"moving trees19.png"],
[UIImage imageNamed:@"moving trees20.png"],
[UIImage imageNamed:@"moving trees21.png"],
[UIImage imageNamed:@"moving trees22.png"],
[UIImage imageNamed:@"moving trees23.png"],
[UIImage imageNamed:@"moving trees24.png"],
[UIImage imageNamed:@"moving trees25.png"],
[UIImage imageNamed:@"moving trees26.png"],
[UIImage imageNamed:@"moving trees27.png"],
[UIImage imageNamed:@"moving trees28.png"],
[UIImage imageNamed:@"moving trees29.png"],
[UIImage imageNamed:@"moving trees30.png"],
[UIImage imageNamed:@"moving trees31.png"],
[UIImage imageNamed:@"moving trees32.png"],
[UIImage imageNamed:@"moving trees33.png"],
[UIImage imageNamed:@"moving trees34.png"],
[UIImage imageNamed:@"moving trees35.png"],
[UIImage imageNamed:@"moving trees36.png"],
[UIImage imageNamed:@"moving trees37.png"],
[UIImage imageNamed:@"moving trees38.png"],
[UIImage imageNamed:@"moving trees39.png"],
[UIImage imageNamed:@"moving trees40.png"],
[UIImage imageNamed:@"moving trees41.png"],
[UIImage imageNamed:@"moving trees42.png"],
[UIImage imageNamed:@"moving trees43.png"],
[UIImage imageNamed:@"moving trees44.png"],
[UIImage imageNamed:@"moving trees45.png"],
[UIImage imageNamed:@"moving trees46.png"],
[UIImage imageNamed:@"moving trees47.png"],
[UIImage imageNamed:@"moving trees48.png"],
[UIImage imageNamed:@"moving trees49.png"],
[UIImage imageNamed:@"moving trees50.png"],
[UIImage imageNamed:@"moving trees51.png"],
[UIImage imageNamed:@"moving trees52.png"],
[UIImage imageNamed:@"moving trees53.png"],
[UIImage imageNamed:@"moving trees54.png"],
[UIImage imageNamed:@"moving trees55.png"],
[UIImage imageNamed:@"moving trees56.png"],
[UIImage imageNamed:@"moving trees57.png"],
[UIImage imageNamed:@"moving trees58.png"],
[UIImage imageNamed:@"moving trees59.png"],
[UIImage imageNamed:@"moving trees60.png"],nil];
// all frames will execute in 1.75 seconds
tree1.animationDuration =1.75;
// repeat the annimation forever
tree1.animationRepeatCount = 0;
// start animating
[tree1 startAnimating];
// add the animation view to the main window
//[bgview addSubview:campFireView];
[tree1 release];
player.numberOfLoops = -1;
[player play];
}
还有其他方法可以使用框架显示动画吗?这种方法似乎更重,而且崩溃很多..
答案 0 :(得分:4)
尝试使用PNG Animation method by Moses DeJong。从他的话来说:
此示例实现动画 简单的定向视图控制器 等待读取PNG图像数据 框架直到需要它为止。代替 alleocating很多兆字节,这个类 在大约半兆的内存中运行 大约有5-10%的CPU利用率 第二代iPhone。
我相信它基本上使用UIImageView来缓存AVAudioPlayer。
答案 1 :(得分:0)
有一个动画回调,类似于动画完成,[self performSelector:@selector(stopAnimation) withObject:nil afterDelay:3];
无法记得 - 但通常的方法是,一旦动画完成,这个方法被调用,然后你可以释放。通常的EXC_BAD_ACCESS可能是您的一个或多个图像不存在,请仔细检查所有图像名称并验证它们是否存在于资源文件夹中。就我所知的动画图像来说,这是唯一的。
帮助链接http://iosdevelopertips.com/graphics/animated-gif-animated-images-iphone-style.html