我想加载一个视图,但是加载需要很长时间,所以我尝试放置一个activityIndicatorView,但是当视图已经加载时它开始运行,当我返回主视图时它仍在运行并且它不会停止.
我该怎么做才能让activityIndicatorView在我点击UIButton时立即启动并在它完成加载时停止?
我已经在堆栈溢出中尝试了所有类似的问题,但没有帮助。
- (IBAction)boletin:(id)sender {
UIImage *statusImage = [UIImage imageNamed:@"1.png"];
activityImageView = [[UIImageView alloc] initWithImage:statusImage];
//Add more images which will be used for the animation
activityImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
[UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"],
[UIImage imageNamed:@"8.png"],
[UIImage imageNamed:@"9.png"],
[UIImage imageNamed:@"10.png"],
[UIImage imageNamed:@"11.png"],
[UIImage imageNamed:@"12.png"],
[UIImage imageNamed:@"13.png"],
[UIImage imageNamed:@"14.png"],
[UIImage imageNamed:@"15.png"],
[UIImage imageNamed:@"16.png"],
[UIImage imageNamed:@"17.png"],
[UIImage imageNamed:@"18.png"],
nil];
//Set the duration of the animation (play with it
//until it looks nice for you)
activityImageView.animationDuration = 0.7;
//Position the activity image view somewhere in
//the middle of your current view
activityImageView.frame = CGRectMake(self.view.frame.size.width/2 - 25, self.view.frame.size.height/2 - 75, 45, 45);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[activityImageView startAnimating];
[self.view addSubview:activityImageView];
dispatch_async(dispatch_get_main_queue(), ^{
[activityImageView stopAnimating];
});
});
}