I ran into a similar UI blocking problem when I used UICollectionView to display and preview videos in a local photo library through ALAssetLibrary .
Scrolling while switching a video does not work smoothly, so I assume some element is blocking the user interface stream. Then I use Core Animation for Instruments to analyze what exactly the user interface thread occupies. In Time Profiler I found that replaceCurrentItemWithPlayerItem takes about 30 ms to execute in the main thread, which is more than 16 ms (1000/60 (fps)) leads to intermittent scrolling.
To solve the problem, I first tried to put replaceCurrentItemWithPlayerItem in the background thread using GCD, but it does not work. I'm not sure if this is because Cocoa itself needs to update the interface when calling replaceCurrentItemWithPlayerItem , which means the UI thread is still blocked. Finally, I started it by putting replaceCurrentItemWithPlayerItem at the end of the scroll (delegate func scrollViewDidEndDecelerating(scrollView: UIScrollView) ). Now scrolling smoothly, yep!
Therefore, my advice is obvious: Using tools to analyze what exactly the user interface thread occupies
source share