我正在尝试在viewDidAppear阶段启动imageView的动画。
我希望在viewDidLoaded阶段加载webview的内容时停止动画。
然而,当调用stopAnimation时,我的UIImageView不会停止动画
在ViewDidLoaded阶段。
任何人都可以告诉我如何在viewDidLoaded上停止动画?
任何帮助将不胜感激。
UIImageView *customActivityIndicator;
-(void)viewDidAppear:(BOOL)animated{
...
customActivityIndicator = [[UIImageView alloc] initWithFrame:CGRectMake(loadingPosX, loadingPosY, loadingImageWidth, loadingImageHeight)];
[self.view addSubview: customActivityIndicator];
customActivityIndicator.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"1.png"],[UIImage imageNamed:@"2"],[UIImage imageNamed:@"3.png"],[UIImage imageNamed:@"4.png"],[UIImage imageNamed:@"5.png"],nil];
customActivityIndicator.animationDuration = 1.0; // in seconds
customActivityIndicator.animationRepeatCount = 0; // sets to loop
[customActivityIndicator startAnimating]; // starts animating
}
- (void)viewDidLoad {
[super viewDidLoad];
....
[webView loadRequest : requestObj];
[customActivityIndicator stopAnimating]; // stop animating
}
答案 0 :(得分:2)
使用 UIWebViewDelegate 和协议方法 webViewDidFinishLoad
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[customActivityIndicator stopAnimating]; // stop animating
}
- (void)viewDidLoad {
[super viewDidLoad];
....
webView.delegate = self;
[webView loadRequest : requestObj];
}