Schlechte Bildlaufleistung von UICollectionView mit UIImage

Ich habe eine UICollectionView in meiner App und jede Zelle ist eine UIImageView und einige Textbeschriftungen. Das Problem ist, dass wenn ich die UIImageViews habe, die ihre Bilder anzeigen, die Bildlaufleistung schrecklich ist. Es ist bei weitem nicht so flüssig wie das Scrollen in einer UITableView oder sogar in derselben UICollectionView ohne die UIImageView.

ich fanddiese Frage Von vor ein paar Monaten, und es scheint, als ob eine Antwort gefunden wurde, aber sie ist in RubyMotion geschrieben und ich verstehe das nicht. Ich habe versucht, es in Xcode umzuwandeln, aber da ich auch noch nie NSCache verwendet habe, ist es etwas schwierig. Das dortige Plakat wies ebenfalls darauf hinHier Ich bin mir aber nicht sicher, wo ich den Code ablegen soll. Möglicherweise, weil ich den Code von der nicht versteheerste Frage.

Könnte jemand helfen, dies in Xcode zu übersetzen?

def viewDidLoad
  ...
  @images_cache = NSCache.alloc.init
  @image_loading_queue = NSOperationQueue.alloc.init
  @image_loading_queue.maxConcurrentOperationCount = 3
  ...
end

def collectionView(collection_view, cellForItemAtIndexPath: index_path)
  cell = collection_view.dequeueReusableCellWithReuseIdentifier(CELL_IDENTIFIER, forIndexPath: index_path)
  image_path = @image_paths[index_path.row]

  if cached_image = @images_cache.objectForKey(image_path)
    cell.image = cached_image
  else
    @operation = NSBlockOperation.blockOperationWithBlock lambda {
      @image = UIImage.imageWithContentsOfFile(image_path)
      Dispatch::Queue.main.async do
        return unless collectionView.indexPathsForVisibleItems.containsObject(index_path)
        @images_cache.setObject(@image, forKey: image_path)
        cell = collectionView.cellForItemAtIndexPath(index_path)
        cell.image = @image
      end
    }
    @image_loading_queue.addOperation(@operation)
  end
end

Hier ist der Code von derzweite Frage dass der Fragesteller deserste Frage sagte das Problem gelöst:

UIImage *productImage = [[UIImage alloc] initWithContentsOfFile:path];

CGSize imageSize = productImage.size;
UIGraphicsBeginImageContext(imageSize);
[productImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
productImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Auch hier bin ich mir nicht sicher, wie / wo ich das implementieren soll.

Danke vielmals.

Antworten auf die Frage(3)

Ihre Antwort auf die Frage