2017-06-09 39 views
0

我目前有一個橫幅可以從我的網站獲取圖片,我可以滾動左側的橫幅並獲得下一張或上一張圖片的權限。不過,我也希望它每5秒自動更換一次圖像。如何在UIView中每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]; 

*以上代碼在忽略動畫部分時工作正常。 謝謝

回答

0

滾動型有一個屬性

setContentOffset:animated: 

使用該財產的NSTimer功能看effect.Follow這thread。它包含如何做到這一步的一步一步的過程。

或者。

您可以使用UIPageViewController和NStimer組合,如this流行的線程。

UIPageVC有一個像這樣的方法。

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

它期望提供數據。然後,您可以使用NSTimer一段時間來顯示圖像。

+0

謝謝。我現在有一種工作方式。我在imageView中添加了一個NStimer,現在每5秒觸發一次。 – Kevin

相關問題