Loading animation



  • I use this code to download files. The problem is the animation of loading. progrssView at the last moment. Not throughout the process. How do we solve the problem?

    Using NSURLSession as advised on the previous issue

    - (void)viewDidLoad
    {
    _progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
        _progressView.progressTintColor = [UIColor colorWithRed:0.0/255 green:0.0/255 blue:0.0/255 alpha:0.4];
        [[_progressView layer]setFrame:CGRectMake(60, 150, 100, 25)];
        [[_progressView layer]setBorderColor:[UIColor whiteColor].CGColor];
        _progressView.trackTintColor = [UIColor clearColor];
        [_progressView setProgress:(float)(50/100) animated:YES];
    
    [[_progressView layer]setCornerRadius:_progressView.frame.size.width / 8];
    [[_progressView layer]setBorderWidth:1];
    [[_progressView layer]setMasksToBounds:TRUE];
    _progressView.clipsToBounds = YES;
    [self.view addSubview:_progressView];
    
    _session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];
    
    [self.progressView setProgress:0 animated:NO];
    

    }



  • Try to update progress:

    dispatch_async(dispatch_get_main_queue(), ^{
                //update UI in main thread.
                [self.progressView setProgress:totalBytesWritten/totalBytesExpectedToWrite animated:YES];
            });  }
    

    And actually add the log to see how often you get the data, how you've advised the top.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2