0

I have a banner currently that gets images from my site, and I can scroll the banners left and rights to get the next or previous image. However, I also want it to change the images automatically every 5 secs.

I tried adding these codes to imageView, but the banner becomes empty not showing any images.

imageView.animateImages = delegate.bannerDetailsArray;
imageView.animationDuration = 5.0;
imageView.animationRepeatCount = 0;
[imageview startAnimating];

I am guessing that the array is where the issue is, but I am currently no clue how to fix it.

Can anyone shred some lights how to make the banner images change every 5 seconds?

-(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];

*The above codes works fine when the animation part ignored. Thank you

Kevin
  • 477
  • 1
  • 5
  • 13

1 Answers1

0

ScrollView has a property

 setContentOffset:animated:

Use this property in NSTimer function to see the effect.Follow this thread. It contains step by step process of how to make this.

Or.

You can use UIPageViewController and NStimer combination like this popular thread.

UIPageVC has a method like this.

- (void)setViewControllers:(NSArray *)viewControllers
                 direction:(UIPageViewControllerNavigationDirection)direction
                  animated:(BOOL)animated
                completion:(void (^)(BOOL finished))completion

It expects a data to deliver. Then you can use NSTimer for a certain period of time to give the image.

elk_cloner
  • 2,049
  • 1
  • 12
  • 13
  • Thank you. I have kind of make it working now. I added a NStimer to the imageView and it now fires once every 5 seconds. – Kevin Jun 10 '17 at 03:55