在启动时使用一组图像添加animation

我是新的iPhone应用程序开发,我试图添加一个图像,我的应用程序的开始。 我创build了一个图像数组,当迭代时应该创build一个animation。

-(void)viewDidLoad { animation = [[UIImageView alloc] init]; animation.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"panda1.png"], [UIImage imageNamed:@"panda2.png"], [UIImage imageNamed:@"panda3.png"], nil]; animation.animationRepeatCount = 2; animation.animationDuration = 2; [animation startAnimating]; [self.view addSubview:animation]; [animation release]; //for loading the webpage at start up NSString *urlAddress = @"http://projects.seng.uvic.ca/fatpanda/m/most_recent.php"; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; //load the request in the UIWebView [webView loadRequest:requestObj]; } 

之所以我放开这个animation,是因为我想删除最后一张图片,所以我可以用UIWebView中的网站视图replace它,并且在最后看到它。 上面的代码编译,但是当我运行它没有图像出现,但网站呢。

任何帮助将不胜感激。

试试这个,我认为你的框架结束了所有的零。

 UIImage * first = [UIImage imageNamed:@"panda1.png"] animation = [[UIImageView alloc] initWithImage:first]; animation.animationImages = [NSArray arrayWithObjects: first, [UIImage imageNamed:@"panda2.png"], [UIImage imageNamed:@"panda3.png"], nil]; 

另外…释放animation不会将其从超级视图中删除。 实际上调用addSubview会增加引用计数到UIImageView并释放它是正确的事情。 当你想从视图中删除它,你将不得不再次在子视图列表中find它,并隐藏它或调用removeFromSuperview。