我有一个动画(一个图像数组),我把它放在viewDidLoad中,因为我希望它在它启动后立即播放。在viewDidLoad中的动画后,我也显示了一个UIWebView中的webview,我想留下来。动画播放(出于某种原因,不是我创建的UIImage),但完成后我无法摆脱它。我尝试过放入计时器并从超级视图中移除动画,但不是将其移除,而是退出应用程序并返回主页面。完成后从viewDidLoad中删除动画
-(void)viewDidLoad
{
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.animationRepeatCount = 4;
animation.animationDuration = 2;
[animation startAnimating];
[self.view addSubview:animation];
//set timer to remove animation from view
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval: 3
target: self
selector: @selector(removeAnimation:)
userInfo: nil
repeats: NO];
//for loading the image at start up
NSString *urlAddress = @"http://projects.seng.uvic.ca/most_recent.php";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//load the request in the UIWebView
[webView loadRequest:requestObj];
}
//removes the animation from subview
- (void) method: (NSTimer*) theTimer
{
[animation release];
[animation removeFromSuperview];
}
oops完全没有注意到缺少的函数名称(仍然习惯这个mac键盘:()添加一个函数名称解决了我的问题。 – panda 2011-03-18 18:44:02