0

I had an UIimageview which animate images and I had a uilabel which describes about the image How to change the label content when we change the image

for (int i=0; i<[mutable_banner count]; i=i+3) 
        {
            NSLog(@"--------%d----------%@",i,[mutable_banner objectAtIndex:i]);
            addr = [mutable_banner objectAtIndex:i];
            addr = [addr stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
            data_banner = [NSData dataWithContentsOfURL:[NSURL URLWithString:addr ] ];
            img_banner = [[UIImage alloc] initWithData:data_banner];

            [images addObject:img_banner];  

        }   


        array = [[NSArray alloc] initWithArray:images];

         NSLog(@"-array-----%d",[array count]);

        imgview_banner = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10,364 ,164)];//364.164
       // [imgview_banner setImage:[UIImage imageWithData:data_banner ]];  

        imgview_banner.animationImages=images;
        imgview_banner.animationDuration=30.0f;
        [imgview_banner startAnimating ];
        [view_banner addSubview:imgview_banner];
4

2 回答 2

0

您可以以与添加图像相同的顺序 存储description所有图像。例如,array[0] 在 imageDescription[0] 中的描述等等。 NSArrayarray

然后当你开始图像动画时,随之调用这个方法

index = 0;
[NSTimer scheduledTimerWithTimeInterval:30.0f target:self selector:@selector(showDesc) userInfo:nil repeats:YES];
[imgview_banner startAnimating ];

然后定义showDesc()方法如下所示:

- (void)showDesc {
    self.label.text = imageDescription[index];
    index ++;
    if (index == array.count) {
        index = 0;
    }
}

将变量声明index为全局变量。

于 2013-06-25T07:29:55.123 回答
0

正如我在您的代码中看到的,您正在使用UIImageView动画,动画持续时间为 30.f 秒,因此要在更改UILabel任何图像时更改文本,您需要设置NSTimertimeInterval为动画设置的相同持续时间,在计时器的目标函数中,您可以相应地更改标签文本,为此您可能需要维护currentIndex以根据图像显示文本,做一些好的条件,它会帮助你。

于 2013-06-25T07:25:17.673 回答