Ios 如何在UIView中每5秒更改一个图像?

Ios 如何在UIView中每5秒更改一个图像?,ios,objective-c,xcode,uiview,nstimer,Ios,Objective C,Xcode,Uiview,Nstimer,我有一个横幅,目前可以从我的网站获得图像,我可以滚动横幅左右,以获得下一个或上一个图像。但是,我也希望它每5秒自动更改一次图像 我尝试将这些代码添加到imageView,但横幅变为空,不显示任何图像 imageView.animateImages = delegate.bannerDetailsArray; imageView.animationDuration = 5.0; imageView.animationRepeatCount = 0; [imageview startAnimatin

我有一个横幅,目前可以从我的网站获得图像,我可以滚动横幅左右,以获得下一个或上一个图像。但是,我也希望它每5秒自动更改一次图像

我尝试将这些代码添加到imageView,但横幅变为空,不显示任何图像

imageView.animateImages = delegate.bannerDetailsArray;
imageView.animationDuration = 5.0;
imageView.animationRepeatCount = 0;
[imageview startAnimating];
我猜数组就是问题所在,但我目前不知道如何修复它

有人能切碎一些灯光吗?如何使横幅图像每5秒更改一次

-(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];
-(无效)横幅设置
{
bannerScrollView=[UIScrollView新建];
[横幅背景色:背景色];
[bannerScrollView设置框:CGRectMake(0,0,delegate.windowWidth,[self-imageWithImage:delegate.windowWidth maxHeight:200]);
[bannerScrollView设置页面启用:是];
[bannerScrollView setContentSize:CGSizeMake([delegate.bannerDetailsArray计数]*delegate.windowWidth,0)];
NSLog(@“%@”,代表bannerDetailsArray);

for(int i=0;iScrollView有一个属性

 setContentOffset:animated:
在NSTimer函数中使用此属性可查看效果。请遵循此操作。它包含如何进行此操作的逐步过程

或。

您可以像流行线程一样使用UIPageViewController和NStimer组合

UIPageVC有这样一个方法

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

它需要传输数据。然后您可以在一定时间内使用NSTimer来提供图像。

谢谢。我现在可以让它工作了。我在imageView中添加了一个NSTimer,它现在每5秒触发一次。