1

我不知道如何解释,但是...如果你理解我说的“加载圈”完美,我只想这样做

    // Start loading in the middle of the screen frozing all interaction
    for (int c = 0; c < ([barcos count] - 1); c++)
    {
        NSArray *datos = [[barcos objectAtIndex:c] componentsSeparatedByString:@";"];
        NSString *nombreImagen = [datos objectAtIndex:2];
        NSURL *accesoFtp = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",urlFtp,nombreImagen]];
        NSData *imagen = [NSData dataWithContentsOfURL:accesoFtp];
        [imagen writeToFile:[[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Barcos/%@",nombreImagen]]] atomically:NO];
    }
    // Stop frozing all interaction and remove the loading circle

可能我必须添加一个线程或其他东西,但我不知道如何做我想要的,我希望你能再次帮助我。谢谢。

编辑:

UIActivityIndicatorView *activityIndicator;
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
activityIndicator.center = self.view.center;
[self.view addSubview: activityIndicator];

activityIndicator.startAnimating;

dispatch_queue_t queue = dispatch_get_global_queue(0,0);

dispatch_async(queue, ^{

        for (int c = 0; c < ([barcos count] - 1); c++)
        {
            NSArray *datos = [[barcos objectAtIndex:c] componentsSeparatedByString:@";"];
            NSString *nombreImagen = [datos objectAtIndex:2];
            NSURL *accesoFtp = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",urlFtp,nombreImagen]];
            NSData *imagen = [NSData dataWithContentsOfURL:accesoFtp];
        [imagen writeToFile:[[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Barcos/%@",nombreImagen]]] atomically:NO];
        }

    dispatch_sync(dispatch_get_main_queue(), ^{
        activityIndicator.stopAnimating;
    });
});

两件事情

 1.- The activity indicator is too small but works, if I can to it bigger or same size but make darker the background would be better (Thanks!)
 2.- I have a warning with startAnimating and stopAnimating "Property access result unused - getters should not be used for side effects"

谢谢 =)

4

6 回答 6

4

可以使用MBProgressHUD完成

还要检查此代码:

//Show your activity indicator here

dispatch_queue_t queue = dispatch_get_global_queue(0,0);

dispatch_async(queue, ^{
    for (int c = 0; c < ([barcos count] - 1); c++)
    {
        NSArray *datos = [[barcos objectAtIndex:c] componentsSeparatedByString:@";"];
        NSString *nombreImagen = [datos objectAtIndex:2];
        NSURL *accesoFtp = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",urlFtp,nombreImagen]];
        NSData *imagen = [NSData dataWithContentsOfURL:accesoFtp];
        [imagen writeToFile:[[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Barcos/%@",nombreImagen]]] atomically:NO];
    }
    dispatch_sync(dispatch_get_main_queue(), ^{
              //hide that activity indicator here
            });

});

编辑:

永远不要调用如下方法:

activityIndicator.startAnimating;
activityIndicator.stopAnimating;

这些用于调用 setter 和 getter。

将其更改为:

[activityIndicator startAnimating];
[activityIndicator stopAnimating];
于 2013-01-23T10:23:11.050 回答
3

您可以使用 UIActivityIndi​​catorView。

UIActivityIndicatorView *activityIndicator;

activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
activityIndicator.center = self.view.center;
[self.view addSubview: activityIndicator];

此外,如 Midhun MP 所示,您可能必须使用异步来例如在指标显示时加载数据。

于 2013-01-23T10:34:15.670 回答
1

也许您可以尝试活动指示器。

于 2013-01-23T10:24:20.827 回答
1

您可以尝试使用svprogresshud

于 2013-01-23T10:28:48.200 回答
1

您可以更改活动指示器的样式,

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActionSheetStyleDefault];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActionSheetStyleBlackOpaque];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActionSheetStyleBlackTranslucent];

使用任何这些样式。

并且此链接可以帮助解决您的第二个问题 xCode“未使用的属性访问结果 - getter 不应用于副作用”

解决方案:而不是使用activityIndicator.startAnimating;activityIndicator.stopAnimating 使用[activityIndicator startAnimating];[activityIndicator stopAnimating];

于 2013-01-23T11:02:44.337 回答
0

更改活动指示器的大小:

activityIndicator.frame = CGRectMake(0.0, 0.0, 80.0, 80.0);
activityIndicator.transform = CGAffineTransformMakeScale(1.75, 1.75);

顺便说一句,如果您正在填充表格视图,您可以考虑在启动活动指示器的同时启用用户交互:

[activityIndicator startAnimating];
tableView.userInteractionEnabled = NO;

并在之后恢复它:

[self.tableView reloadData];
[activityIndicator stopAnimating];
tableView.userInteractionEnabled = YES;
于 2015-07-25T19:29:43.987 回答