J'ai actuellement une bannière qui obtient des images de mon site, et je peux faire défiler les bannières à gauche et les droits pour obtenir l'image suivante ou précédente. Cependant, je veux aussi qu'il change les images automatiquement toutes les 5 secondes.Comment passer à une autre image toutes les 5 secondes dans UIView?
J'ai essayé d'ajouter ces codes à imageView, mais la bannière devient vide et ne montre aucune image.
imageView.animateImages = delegate.bannerDetailsArray;
imageView.animationDuration = 5.0;
imageView.animationRepeatCount = 0;
[imageview startAnimating];
Je devine que le tableau est où la question est, mais je suis actuellement aucune idée de comment y remédier.
Quelqu'un peut-il déchiqueter quelques lumières comment faire changer les images de bannière toutes les 5 secondes?
-(void) bannerSettings
{
bannerScrollView = [UIScrollView new];
[bannerScrollView setBackgroundColor:BackGroundColor];
[bannerScrollView setFrame:CGRectMake(0,0,delegate.windowWidth, [self imageWithImage:delegate.windowWidth maxHeight:200])];
[bannerScrollView setPagingEnabled:YES];
[bannerScrollView setContentSize:CGSizeMake([delegate.bannerDetailsArray count]*delegate.windowWidth, 0)];
NSLog(@"%@",delegate.bannerDetailsArray);
for(int i=0;i<[delegate.bannerDetailsArray count];i++)
{
UIImageView * imageView = [UIImageView new];
[imageView setFrame:CGRectMake(i*delegate.windowWidth,0,delegate.windowWidth,[self imageWithImage:delegate.windowWidth maxHeight:200])];
[imageView sd_setImageWithURL:[NSURL URLWithString:[[delegate.bannerDetailsArray objectAtIndex:i]objectForKey:@"bannerImage"]]];
[imageView setContentMode:UIViewContentModeScaleAspectFill];
[imageView.layer setMasksToBounds:YES];
[imageView setUserInteractionEnabled:YES];
[imageView setTag:i];
//imageView.animateImages = delegate.bannerDetailsArray;
//imageView.animationDuration = 3.0;
//imageView.animationRepeatCount = 0;
//[imageview startAnimating];
[bannerScrollView addSubview:imageView];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bannerGestureTapped:)];
[imageView addGestureRecognizer:singleTap];
* Les codes ci-dessus fonctionnent correctement lorsque la partie animation est ignorée. Merci
Merci. Je l'ai fait fonctionner maintenant. J'ai ajouté un NStimer à l'imageView et il se déclenche maintenant toutes les 5 secondes. – Kevin