Xóa bài viết
Bạn có chắc chắn muốn xóa bài viết này không ?
Xóa bình luận
Bạn có chắc chắn muốn xóa bình luận này không ?
Work with vanilla UICollectionViewCell
Problem
Sometimes, you'll work with a very big UICollectionView, ex: A cell contains a UICollectionView, a cell contains a UITableView, a cell contains a bundle UIView and a lot of Auto Layout constraint.
Especially, in that cell contains UIImageView, when you scroll on the screen, it's laggy.
How to solve that
Determine issues
Why does it happen?
- Rendering UIImage on UIImageView is take time.
- Draw the Image when scrolling is take time.
- Auto Layout is take time.
- Draw UIImageView is take time.
- Caching on disk is take time.
How I solve that?
- For rendering UIImage on UIImageView, firstly, avoid use native setUIImage method or setImageWithURL of AFNetworking now. Why?. Look at SDWebImage and see what happen :)
- For drawing the Image when scrolling, use below method when setup cell.
objc cell.layer.shouldRasterize = YES; cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
- For Auto Layout, it is a problem on iOS 8, make the cell have auto layout scroll very laggy. So this is solution: Override 1 method in UICollectionViewCell class.
objc - (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes { return layoutAttributes; }
- For the problem of UIImageView, some properties of it will decrease the performance, ex: clipToBounds
- Writting and Reading on Disk is taked more time than Memory, therefore, take care when working with Caching.
Bình luận

{{ comment.user.name }}
Bỏ hay
Hay

Cùng một tác giả

29
4
Đọc 1 quyển sách của Apple là có thể tự trả lời 80% những câu hỏi ngu ngơ của bạn. Mình có tham gia 1 cộng đồng iOS, các bạn tham gia và hỏi đáp n...
Bài viết liên quan

2
3
Xin chào mọi người. Mình xin chia sẽ một UILabel Helper nhỏ dùng trong truờng hợp cần tính chiều cao của UILabel để xác định "Show More" button có ...

14
4
(Link) (Link) (Link) Ở 2 phần tut trước, mình đã hướng dẫn khá chi tiết cách viết một ứng dụng camera có tích hợp chức năng nhận diện khuôn mặ...