简体   繁体   中英

UIImageView stopAnimation not working on viewDidLoad?

I am trying to start imageView's animation on viewDidAppear phase.

I would like to stop animation when content of webview loaded on viewDidLoaded phase.

However my UIImageView does not stop animation when stopAnimation is called

on ViewDidLoaded phase.

can anybody tell me what should I do to stop animation on viewDidLoaded?

any help will be appreciated.

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  
}

Use the UIWebViewDelegate and protocol method webViewDidFinishLoad

- (void)webViewDidFinishLoad:(UIWebView *)webView
 {
    [customActivityIndicator stopAnimating]; // stop animating  
 }

- (void)viewDidLoad { 
    [super viewDidLoad];
    ....
    webView.delegate = self;
    [webView loadRequest : requestObj];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM