0

I'm trying to do some animation to my UIProgressView when i finished upload a photo to my server. When i set the duration to 5.0 or 10.0 seconds, it it not different and the completition is called immediately.

    [UIView animateWithDuration:5.0 animations:^{
        self.progressBar.progress = 1.0;
    } completion:^(BOOL finished) {
        NSLog(@"kykny udah");
        if (finished) {
            NSLog(@"finished");
            Post *post = [mappingResult.dictionary objectForKey:@""];
            [self.posts insertObject:post atIndex:0];

            NSLog(@"caption: %@ , items: %@",post.caption, post.items);

            CGRect frame = self.progressView.frame;
            frame.size.height = 0;
            self.progressView.frame = frame;

            [self.tableView reloadData];
        }
    }];

how come this issue happens ? It is just like a normal sequence code in reality

calvin sugianto
  • 610
  • 7
  • 27
  • Have you tried this same code in iOS 9 or earlier versions ? – NeverHopeless Nov 10 '16 at 06:22
  • 1
    See http://stackoverflow.com/questions/23803464/uiview-animatewithduration-and-uiprogressview-setprogress – clemens Nov 10 '16 at 06:28
  • BTW: You should not misuse animations for timers. The _controller code_ should not be done in the completion block. Why should the user wait for an operation which can be done immediately? Why don't you hide the progress view setting it's `hidden` property to `YES`? – clemens Nov 10 '16 at 06:36
  • because then i hide my progressView, my tableView won`t go to the top and it makes the gap with the height of my progressView – calvin sugianto Nov 10 '16 at 06:40
  • @macmoonshine i have seen that, and i have check if `finished` parameter as you can see in my code above, and i have try to include the dispatch function, but still, it is weird – calvin sugianto Nov 10 '16 at 07:10

2 Answers2

0

Try adding the following line after updating your frame changes like

self.progressBar.progress = 1.0;
[self.view layoutIfNeeded];

This will make your animation effect for the time you specified in animation duration.

Bharath
  • 2,064
  • 1
  • 14
  • 39
-1

If you want to show just the progress for 10sec then

// PROGRESS VIEW IS JUST A VIEW WITH SOME BACKGROUND COLOR WITH FRAME CGRectMake(0,0,0,10)
[UIView animateWithDuration:5.0 animations:^{
self.progressView.frame = CGRectMake(0,0,100,10); // adjust the frame to get  the linear animation view
} completion:^(BOOL finished) {
NSLog(@"kykny udah");
if (finished) {
    .....
    self.progressView.frame = CGRectMake(0,0,100,0);
    .....
}
}];
Santhosh
  • 164
  • 6