UICollectionView Desplazamiento entrecortado al cargar celdas
Tengo una galería en mi aplicación utilizando un UICollectionView
. Las celdas tienen un tamaño aproximado de 70,70. Estoy usando ALAssets
desde el ALAssetLibrary
en la galería que he almacenado en una lista.
Estoy usando el patrón habitual para rellenar las celdas:
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
mycell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
mycell.imageView.image = [[UIImage imageWithCGImage:[alassetList objectAtIndex:indexpath.row] thumbnail]];
return mycell;
}
Mi galería se desplaza entrecortada. No entiendo por qué es esto. He intentado agregar un NSCache para almacenar en caché las imágenes en miniatura (pensando que tal vez crear las imágenes era caro), pero esto no ayudó para el rendimiento.
Me gustaría espere que la interfaz de usuario sea tan mantecosa como la aplicación de valores.
Ahora estoy sospechando que puede ser algo en el UICollectionViewCell prepareForReuse
que puede estar sosteniendo el método dequeueReusableCellWithReuseIdentifier
pero usando instrumentos no fui capaz de encontrar esto.
¿Alguna otra cosa que pueda estar causando esto? ¿Hay una manera "más rápida" de preparar los UICollectionViewCell
o para dequeue
de una manera más rápida?
6 answers
Así que cualquiera que tenga problemas de desplazamiento debe hacer esto
Añadir estas 2 líneas después de su dequeue
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:34:22
Asumiría que el "choppyness" proviene de la asignación UIImage, no nada con el método dequeueReusableCellWithReuseIdentifier
. Intentaría hacer la asignación de imágenes en un hilo de fondo y ver si eso hace que las cosas sean un poco más mantecosas.
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
mycell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {
// Load image on a non-ui-blocking thread
UIImage *image = [[UIImage imageWithCGImage:[alassetList objectAtIndex:indexpath.row] thumbnail]];
dispatch_sync(dispatch_get_main_queue(), ^(void) {
// Assign image back on the main thread
mycell.imageView.image = image;
});
});
return mycell;
}
Puede encontrar más detalles aquí: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-18 06:00:01
Cargue sus imágenes usando sendAsynchronousRequest:queue:completionHandler:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
[cell.imageView setImage:[UIImage imageWithData:data]];
}];
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-04 09:42:03
Marque las subviews de clip y opaco en el inspector de atributos y marque la opción de paginación habilitada.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-27 05:45:45
Si alguien está usando PHImageManager, desactivar synchronous solucionó el problema. (deliveryMode = .FastFormat también puede dar una mejora adicional del rendimiento, pero la compensación es que la miniatura será de menor calidad)
let option = PHImageRequestOptions()
option.deliveryMode = .Opportunistic
option.synchronous = false
PHImageManager().requestImageForAsset(phAsset, targetSize: CGSizeMake(2048, 2048), contentMode: .AspectFit, options: option, resultHandler: { (image, objects) in
self.imageView.image = image!
})
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-17 17:06:24
Tuve problemas con el desplazamiento UICollectionView
.
Lo que funcionó (casi) como un encanto para mí: Poblé las celdas con miniaturas png 90x90. Digo casi porque el primer desplazamiento completo no es tan suave, pero nunca se estrelló más...
En mi caso, el tamaño de la celda es 90x90.
Tenía muchos tamaños PNG originales antes, y era muy entrecortado cuando el tamaño original png era mayor que ~1000x1000 (muchos bloqueos en el primer desplazamiento).
Así que selecciono 90x90 (o similar) en el UICollectionView
y mostrar los PNGS originales (sin importar el tamaño). Espero que esto ayude a otros.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-20 22:34:29