iOS - UIView animateWithDuration无法正常工作

时间:2016-11-10 06:02:18

标签: objective-c iphone ios10 uiprogressview

当我完成将照片上传到我的服务器时,我试图为我的UIProgressView做一些动画。当我将持续时间设置为5.0或10.0秒时,它没有不同,并且立即调用completition。

    [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];
        }
    }];

为什么会出现这个问题?它就像现实中的普通序列码一样

2 个答案:

答案 0 :(得分:0)

尝试在更新框架更改后添加以下行,例如

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

这将使您的动画效果达到您在动画持续时间中指定的时间。

答案 1 :(得分:-1)

如果您想仅显示10秒的进度,那么

// 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);
    .....
}
}];