2

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

首先它必须加载

[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 天开始尝试它。

提前致谢

4

1 回答 1

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];    
}
于 2013-10-29T07:47:50.817 回答