0

我正在尝试在调用 Web 服务时进行加载视图...我已经尝试过:

-(void) viewDidLoad {
[NSThread detachNewThreadSelector:@selector(workerThread) toTarget:self withObject:nil];
//here I call the thread before call web service
 }


 -(void) workerThread {
[viewLoading setHidden:NO];
[NSThread detachNewThreadSelector:@selector(threadAnimacao) toTarget:self withObject:nil];
}


 -(void) threadAnimacao { //call this function is ok, but the timerLoadingEvento only is called after the call webservice ends
contadorLoading = 0;
nVoltas = 0;
nEspera = 0;
timerLoading = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerLoadingEvento:) userInfo:nil repeats:YES]; 
}


-(void)timerLoadingEvento:(NSTimer *)theTimer{
UIImageView *img = imgLoading;

if (nEspera == 0) {
    if(contadorLoading == 0)
        [img setImage:[UIImage imageNamed:@"frame_01.png"]];
    else if(contadorLoading == 1)
        [img setImage:[UIImage imageNamed:@"frame_02.png"]];
    else if(contadorLoading == 2)
        [img setImage:[UIImage imageNamed:@"frame_03.png"]];
    else if(contadorLoading == 3)
        [img setImage:[UIImage imageNamed:@"frame_04.png"]];
    else if(contadorLoading == 4)
        [img setImage:[UIImage imageNamed:@"frame_05.png"]];
    else if(contadorLoading == 5)
        [img setImage:[UIImage imageNamed:@"frame_06.png"]];
    else if(contadorLoading == 6)
        [img setImage:[UIImage imageNamed:@"frame_07.png"]];
    else if(contadorLoading == 7)
        [img setImage:[UIImage imageNamed:@"frame_08.png"]];
    else if(contadorLoading == 8)
        [img setImage:[UIImage imageNamed:@"frame_09.png"]];
}

contadorLoading++;
nVoltas++;

if(nEspera != 0)
    nEspera++;

if(nEspera>250) {
    nEspera = 0;
    contadorLoading = 0;
    nVoltas = 0;
}

if(contadorLoading == 8)
    contadorLoading = 0;

if(nVoltas == 9)
    nEspera = 1;
 }
4

1 回答 1

1

您可以在 Web 服务调用结束时使用默认活动指示器

或者,如果您有用于进度的自定义图像

您可以尝试将 animationImages(UIImage 对象数组)添加到 UImageView,设置动画重复计数(0 表示无限期)和 imageview 的动画持续时间并调用 imageview 开始动画以及一旦 Web 服务完成就调用停止动画。

查看 UIImageView API 指南以获取更多详细信息。

希望这可以帮助 !!!

于 2013-03-08T12:57:53.110 回答