5
시간의 90 %에서 작동하는 카메라 미리보기 창이 있습니다. 그러나 배경에있는 경우 내 앱으로 돌아갈 때 미리보기가 표시되지 않는 경우가 있습니다. 이 뷰를로드 할 때 내가 전화 코드입니다 :배경에서 돌아올 때 AVCaptureSession이 실패합니다.
- (void) startCamera {
session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetPhoto;
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.frame = _cameraView.bounds;
[_cameraView.layer addSublayer:captureVideoPreviewLayer];
captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
captureVideoPreviewLayer.position=CGPointMake(CGRectGetMidX(_cameraView.bounds), 160);
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
NSLog(@"ERROR: %@", error);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Important!"
message:@"Unable to find a camera."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert autorelease];
}
[session addInput:input];
stillImage = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG , AVVideoCodecKey, nil];
[stillImage setOutputSettings:outputSettings];
[session addOutput:stillImage];
[session startRunning];
}
이 경우, 내 기본보기로 전환 할 수 있으며 다시과 알이 잘이지만, 내가 죽이고 싶은 성가신 버그. 미리보기 창은 내 스토리 보드의 UIView입니다.
감사합니다. 몇 시간 동안 테스트 해 보겠습니다. – mrEmpty
환상적인 해결책 ....... –
기다림 -'viewWillAppear' /'Disappear' 만 호출되는 경우가 아닙니까? 장면이 앱에서 움직이는 것처럼 : 앱이 전경을오고 갈 때 호출되지 않습니다. 'UIApplicationWillResignActiveNotification'에 등록 할 필요가 없을까요? [그 예와 품질 보증] (http://stackoverflow.com/a/22868754/294884) – Fattie