在ios中以指定的时间戳一个接一个地加载图像

时间:2013-10-29 07:42:03

标签: ios

我正在尝试在屏幕顶部放置横幅,并在特定时间戳[ex:20sec]的横幅中加载不同的图像。

首先必须加载

[A] B C D E ,
A [B] C D E,
A B [C] D E,
A B C [D] E,
A B C D [E],
[A] B C D E,

自动我在过去2天尝试过。

提前致谢

1 个答案:

答案 0 :(得分:3)

使用此代码:

    NSArray *imagesArray =   [[NSArray alloc]initWithObjects:[UIImage imageNamed:@"imgA.png"] ,[UIImage imageNamed:@"imgB.png"] ,[UIImage imageNamed:@"imgC.png"] ,[UIImage imageNamed:@"imgD.png"] ,[UIImage imageNamed:@"imgE.png"] , nil];
    UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    imageView.animationImages = imagesArray;
    imageView.animationDuration = 20*[imagesArray count]; // 20 is for the timestamp
    imageView.animationRepeatCount = -1;  // -1 for making the loop for ever, or you can use HUGE_VALF
    [self.view addSubview:imageView];
    [imageView startAnimating];    

<强>更新

要使滑动动画使用此动画:

 NSArray *imagesArray;
 int photoCount;
 UIImageView *imageView;
-(void)setupImageView{
     photoCount = 0;
     [[NSArray alloc]initWithObjects:[UIImage imageNamed:@"imgA.png"] ,[UIImage imageNamed:@"imgB.png"] ,[UIImage imageNamed:@"imgC.png"] ,[UIImage imageNamed:@"imgD.png"] ,[UIImage imageNamed:@"imgE.png"] , nil];         imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
     imageView.image = [imagesArray objectAtIndex:photoCount];
     [self.view addSubview:imageView];
     [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:@selector(transitionPhotos) userInfo:nil repeats:YES];

 }

 -(void)transitionPhotos{


if (photoCount < [imagesArray count] - 1){
    photoCount ++;
}else{
    photoCount = 0;
}
[UIView transitionWithView:self.imageView1
                  duration:2.0
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{ imageView.image = [imagesArray objectAtIndex:photoCount]; }
                completion:NULL];    
}