UIActivityIndicatorView not spinning

I have this problem when I add UIActivityIndicatorViewto UIScrollView; Everything works fine, except that it does not start spinning if it scrolls UIScrollView.

Can someone help me with this problem?

Thank.

here is the code:

    UIActivityIndicatorView *loaderActivity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    loaderActivity.center = CGPointMake(87/2,y+56/2);
    loaderActivity.tag=tag;
    [mainScrollView addSubview:loaderActivity];
    [loaderActivity startAnimating];
    [loaderActivity release];
+5
source share
5 answers

You need to call startAnimatingthe activity indicator so that it is the same. Alternatively, in the interface builder, you can select the animating check box.

+5
source

, , , , startAnimating . UIKit .

, , :

if ([NSThread isMainThread]) {
    NSLog(@"Running on main thread.");
} else {
    NSLog(@"Running on background thread.");
}

, , , . , , :

// this code would be wherever your existing code was
[self performSelectorOnMainThread:@selector(addActivityIndicatorToView:) withObject:mainScrollView waitUntilDone:YES];

// this would be a new method in the same class that your existing code is in
- (void) addActivityIndicatorToView:(UIView*) view {
    UIActivityIndicatorView *loaderActivity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    loaderActivity.center = CGPointMake(87/2,y+56/2);
    loaderActivity.tag=tag;
    [view addSubview:loaderActivity];
    [loaderActivity startAnimating];
    [loaderActivity release];
}
+3
activityIndicator = [[UIActivityIndicatorView alloc] 
initWithFrame:CGRectMake(87/2,y+56/2);
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.tag=tag;
[mainScrollView addSubview:loaderActivity];
[activityIndicator startAnimating];
[activityIndicator release];
+2
source

Try running the animator on a different thread.

NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(showProgress) object:nil];
[thread start];

//do whatever your want here

//call this when you want it stop animating
    [activityIndicator stopAnimating];
    [thread release];


- (void)showProgress{

    [activityIndicator startAnimating];

}
0
source

There was a problem when I made a call startAnimatingin viewDidLoadand did not work. I moved the call to viewWillAppearand it will work!

0
source

All Articles