How start animation of activity indicator when cli

2019-09-07 04:41发布

问题:

I have code in which I have array of view in scroll view. In each view I create image view and button. Now i want to set a event on button that is when click on button then activity indicator will appear on view and start animation and when finish upload of next view or image then stop and hide activity indicator. What I will do in code so that it work? How do that? In short i want to display activity indicator on view when click on button and hide when neat view appear.

回答1:

make a function and call that on button click, and add this code in your function

    spinner = [[UIActivityIndicatorView alloc]    initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [spinner setCenter:CGPointMake(480/2.0, 128.0/2)]; // (mid of screen) I do this because I'm in landscape mode
    [yourView addSubview:spinner];  
    [spinner startAnimating];       
    [spinner release];  

Use this to remove the spinner: [spinner removeFromSuperview];

here spinner is, UIActivityIndicatorView *spinner; (I've declared in .h of ma code)