0

I want to use photos I parse from my API to make an UIImageView animate.

I get an the urls of the photos in an array but I can't figure out how to download the photos, put them in an array and then in the image view.

Could anyone help me with this? I can't figure it out :(

Thanks in advance.

4

3 に答える 3

1

NSData メソッドを使用してそれらをダウンロードする必要があります: initWithContentsOfURL:options:error、次にこの NSData から UIImage を作成します。

すべての画像をダウンロードし、UIImage の配列を取得したら、その配列を使用して UIImageView の animationImages プロパティを設定します。

もちろん、UI をブロックしないように、スレッドで画像をダウンロードします。

于 2013-10-29T12:39:34.130 に答える
0

このダウンロード画像を使用

または、AFNetworking ライブラリリンクを使用して画像をダウンロードします。ライブラリをダウンロードし、AFNetworking フォルダーをプロジェクトに追加します。必要なフレームワーク (Security、MobileCoreServices、および SystemConfiguration) を追加し、AFImageRequestOperation クラスを使用します。

このコードを使用して画像をダウンロードします

    -(void)downloadImage:(NSString *)imageUrl {

    // download the photo

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:imageUrl]];
    AFImageRequestOperation *operation = [AFImageRequestOperation
                                          imageRequestOperationWithRequest:request
                                          imageProcessingBlock:nil
                                          success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
                                          {
                                              if (image != nil) {
                                                  NSLog(@"image downloaded %@", image);
                                                  [self.imageArray addObject:image];
                                              }

                                             //put code to add image to image view here 
                                          } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
                                              NSLog(@" error %@", error.description);

                                          }];

    [operation start];


}
于 2013-10-29T13:50:27.817 に答える
0

URL から imageview に画像を追加するには、ソリューションは簡単です。

imageView.image = [UIImage imageWithContentsOfURL:theURL];

多くの画像については、非同期でロードして画像キャッシュを使用する方がよいと考えられています。これには、SDWebImage などのオープン ソース ライブラリが多数あります。

于 2013-10-29T12:40:40.413 に答える