Ios 滚动UICollectionView块主线程

Ios 滚动UICollectionView块主线程,ios,grand-central-dispatch,Ios,Grand Central Dispatch,我有一个使用AVSampleBufferDisplayLayer播放H264的视频解码器,在我在同一个视图控制器上滚动UICollectionViewController之前,一切都很好。这似乎阻止了主线程,导致应用程序崩溃。我曾尝试使用dispatch_async将此代码放入单独队列的块中,但仍然存在相同的块问题以及解码器上的进一步性能问题 dispatch_async(sampleQueue, ^{ [sampleBufferQueue ad

我有一个使用AVSampleBufferDisplayLayer播放H264的视频解码器,在我在同一个视图控制器上滚动UICollectionViewController之前,一切都很好。这似乎阻止了主线程,导致应用程序崩溃。我曾尝试使用dispatch_async将此代码放入单独队列的块中,但仍然存在相同的块问题以及解码器上的进一步性能问题

dispatch_async(sampleQueue, ^{

                        [sampleBufferQueue addObject:(__bridge id)(sampleBuffer)];

                        if ([avLayer isReadyForMoreMediaData]) {
                            CMSampleBufferRef buffer = (__bridge CMSampleBufferRef)([sampleBufferQueue objectAtIndex:0]);
                            [sampleBufferQueue removeObjectAtIndex:0];
                            [avLayer enqueueSampleBuffer:buffer];
                            buffer = NULL;

                            NSLog(@"I Frame");
                            [avLayer setNeedsDisplay];
                            while ([sampleBufferQueue count] > 0 && [avLayer isReadyForMoreMediaData]) {

                                CMSampleBufferRef buffer = (__bridge CMSampleBufferRef)([sampleBufferQueue objectAtIndex:0]);
                                [sampleBufferQueue removeObjectAtIndex:0];
                                [avLayer enqueueSampleBuffer:buffer];
                                buffer = NULL;
                                NSLog(@"I Frame from buffer");
                                [avLayer setNeedsDisplay];
                            }
                        }
                        else {
                            NSLog(@"AVlayer Not Accepting Data (I)");
                        }
                    });

有没有一种方法可以让此任务优先于用户界面操作,如滚动集合视图等?抱歉,我对IOS不太了解。

原来UICollectionView在主线程上阻止了对NSURLConnection的委托调用。这就解决了问题:

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
                                                          delegate:self];
改为

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
                                                          delegate:self
                                                  startImmediately:NO];
[connection scheduleInRunLoop:[NSRunLoop currentRunLoop]
                  forMode:NSRunLoopCommonModes];
[connection start];