我正在做一个需要验证QR代码的iOS应用程序,其层次结构如下:
View
---Scan View
---Image View - cardBG
---Inside View问题在第3步:当我停止AVCaptureSession时,即使是在in this question这样的异步调度中,刷新视图也需要8-10秒。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if([_captureSession isRunning])[_captureSession stopRunning];
AVCaptureInput* input = [_captureSession.inputs objectAtIndex:0];
[_captureSession removeInput:input];
AVCaptureVideoDataOutput* output = (AVCaptureVideoDataOutput*)[_captureSession.outputs objectAtIndex:0];
[_captureSession removeOutput:output];
});
[self.bgImageView setHidden:NO];
[self.insideView setHidden:NO];
[self.scanView setHidden:YES];
[self.previewLayer removeFromSuperlayer];我的问题是:我如何才能避免这种冻结呢?
发布于 2014-02-18 05:02:37
没有更多的背景就很难说了。这取决于究竟是什么导致了延迟。像这样的东西有用吗?
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if([_captureSession isRunning])[_captureSession stopRunning];
dispatch_async(dispatch_get_main_queue(), ^{
[self.bgImageView setHidden:NO];
[self.insideView setHidden:NO];
[self.scanView setHidden:YES];
[self.previewLayer removeFromSuperlayer];
});
AVCaptureInput* input = [_captureSession.inputs objectAtIndex:0];
[_captureSession removeInput:input];
AVCaptureVideoDataOutput* output = (AVCaptureVideoDataOutput*)[_captureSession.outputs objectAtIndex:0];
[_captureSession removeOutput:output];
});发布于 2014-02-18 05:13:33
以下代码将对您有所帮助:
if(self.previewLayer) {
[self.previewLayer removeFromSuperlayer];
self.previewLayer = nil;
}
if(_captureSession) {
[_captureSession stopRunning];
_captureSession = nil;
}https://stackoverflow.com/questions/21844675
复制相似问题