2014-09-01 102 views
-3

我想要自動一個一個地滑動圖像我正在從圖像路徑從服務器獲取圖像,但它始終只顯示一個圖像我應該怎麼做?圖像不動畫

for (SliderDC *slider in imagesArray) { 
     sliderImageName = slider.sliderImagePath; 
      NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@%@",kWSURL, sliderImageName]]]; 
      UIImage *imgOne = [UIImage imageWithData:imageData]; 
    ////  likely download all images from web service and create an array like 
    // 
      NSArray *imagesArrays = [NSArray arrayWithObjects:imgOne, nil]; 

////  and use with little modification 
    // 
     UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds]; 
     animatedImageView.animationImages = imagesArrays; 
     animatedImageView.animationDuration = 0.5f; 
     animatedImageView.animationRepeatCount = 0; 

     [self.view addSubview: animatedImageView]; 
     [animatedImageView startAnimating]; 
    } 
+0

我不明白。你只有一個圖像(在'imagesArays'中)。那應該是怎樣的動畫?你讀過如何使用它? – Larme 2014-09-01 08:19:52

回答

2

因爲您的數組全部只包含1個圖像。你的代碼應該如下所示。

NSMutableArray *imagesArrays= [[NSMutableArray alloc]init]; 
for (SliderDC *slider in imagesArray) { 
    sliderImageName = slider.sliderImagePath; 
     NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@%@",kWSURL, sliderImageName]]]; 
     if(imageData) 
      UIImage *imgOne = [UIImage imageWithData:imageData]; 
      if(imgOne) 
       [imagesArrays addObject:imgOne]; 
} 

// after adding all image in array then add animation. 
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds]; 
animatedImageView.animationImages = imagesArrays; 
animatedImageView.animationDuration = 0.5f; 
animatedImageView.animationRepeatCount = 0; 

[self.view addSubview: animatedImageView]; 
[animatedImageView startAnimating]; 
+0

我不是給相同的數組plz檢查它是不同的名字imagesArrays不是圖像數組 – NullData 2014-09-01 08:17:43

+0

爲什麼要投票? – NullData 2014-09-01 08:18:01

+0

我沒有downvote。當你想添加動畫時,你必須給出你想要的所有圖像的數組。現在'NSArray * imagesArrays = [NSArray arrayWithObjects:imgOne,nil];'此代碼只包含1個圖像,並且您開始動畫。你必須在'animatedImageView.animationImages = imagesArrays;'這個代碼中傳遞圖像數組。 – 2014-09-01 08:19:32