3

私は iPhone プログラミングの初心者です。以下のコードを使用すると、バックグラウンドでサーバーから画像をすばやく非同期に取得できます。

画像を15枚まとめてダウンロードしたい。ユーザーが下にスクロールすると、次の 15 枚の画像をダウンロードして表示できます。また、表示されなくなった画像をアンロードして削除したい。したがって、バッチで画像をダウンロードしたいのですが、1000 個の画像がある場合は、0-15、15-30、30-45 などとしてダウンロードしたいと考えています。

どうすればこれを実装できますか?

そして、LazyloadingまたはSDWebimageソースコードプロジェクトを使用して、私が言ったような画像を取得できますが、画像を3 * 3のサムネイルに表示したい(各行に3つの画像を表示したいことを意味します)どのようにすればよいか教えてください。 Androidのユニバーサルライブラリのようなライブラリが欲しい

  //remote image URLs
        URLs = [[NSMutableArray alloc]init];

              for (NSString *path in latestiamge)
        {

            NSURL *URL = [NSURL URLWithString:path];
            if (URL)
            {
                [URLs addObject:URL];

            }
            else
            {
            }
        }

        self.imageURLs = URLs;

        UISwipeGestureRecognizer* swipeUpGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeUpFrom:)];
        swipeUpGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
        [myScrollView addGestureRecognizer:swipeUpGestureRecognizer];

        float horizontal = 2.0;
        float vertical = 2.0;

        for(int i=0; i<[imageURLs count]; i++)

        {
            if((i%3) == 0 && i!=0)
            {
                horizontal = 5.0;
                vertical = vertical + 100.0 + 5.0;
            }
            CGRect frame;
            frame.size.width=100.0;
            frame.size.height=100.0;
            frame.origin.x=0;
            frame.origin.y=0;
            AsyncImageView *imageView = [[AsyncImageView alloc] initWithFrame:frame];
            imageView.contentMode = UIViewContentModeScaleAspectFill;
            imageView.clipsToBounds = YES;
            imageView.tag = i;
            //load the image
            imageView.imageURL = [imageURLs objectAtIndex:i];

            UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]
                                                 initWithTarget:self
                                                 action:@selector(actionHandleTapOnImageView:)];
            imageView.userInteractionEnabled = YES;
            [imageView addGestureRecognizer:singleTap];
            [myScrollView addSubview:imageView];

            buttonImage1 = [UIButton buttonWithType:UIButtonTypeCustom];
            [buttonImage1 setFrame:CGRectMake(horizontal, vertical, 100.0, 100.0)];
            [buttonImage1 setTag:i];

            [buttonImage1 setImage:[idURLs objectAtIndex:i] forState:UIControlStateNormal];
            [buttonImage1 setImage:[UIImage imageNamed:@"Overlay.png"] forState:UIControlStateSelected];


            [myScrollView addSubview:buttonImage];

            [buttonImage1 addSubview:imageView];
            [myScrollView addSubview:buttonImage1];


           horizontal = horizontal + 100.0 + 5.0;

        }
        [myScrollView setContentSize:CGSizeMake(320.0, vertical + 3900.0)];
4

1 に答える 1

4

すべての作業の背後にある概念を学ぶことに興味がある場合は、基本的な理解のために以下を参照してください。

http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial

http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues

また、非同期ロードを使用したいだけの場合。これを使うことをお勧めします。UIImage に基づいています。とても良いです

https://github.com/rs/SDWebImage.git

これらすべてを調べて楽しむことをお勧めします。

于 2013-07-08T07:08:20.113 に答える