Animating the offset of the scrollView in a UICollectionView/UITableView causes prematurely disappearing cells

孤街醉人 提交于 2019-12-04 02:49:19

I went with #2. Here's the snippet that does the rendering and storing:

UIGraphicsBeginImageContext(theCell.bounds.size);
[theCell.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *renderedCellImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

The rest of the method was pretty much as I described above, with one caveat: this has to be done before the image is actually used and on a background thread, because rendering can take up to 1 full second on an iPhone 4. Hope this helps somebody.

I got the cells to stay visible by reloading them immediately after setting the content offset in the animation block.

UIView.animateWithDuration(0.3) { 
    self.collectionView.contentOffset = newOffset
    self.collectionView.reloadItemsAtIndexPaths(willDisappearIndexPaths)
}

LongShot: Try to set the UIView animation block options to UIViewAnimationOptionBeginFromCurrentState.

[UIView animateWithDuration:1
                      delay:0
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{ }
                 completion:^(BOOL  completed){ } ];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!