주 뷰를 형제 하위 뷰로 제어하는보기 컨트롤러가 있습니다. 하나는 IB에서 가져온 버튼과 레이블 및 물건이있는 overlayView라고하는 뷰입니다. 다른 하나는 웹캠에서 AVCaptureVideoPreviewLayer를 유지하기 위해 프로그래밍 방식으로 추가하는 captureLayer라는 것입니다. 어떤 이유로 오버레이 레이어를 미리보기 레이어 위에 표시 할 수 없습니다.OSX에서 AVCaptureVideoPreviewLayer를 사용하여 코코아보기 순서 오버레이가 이상하게 작동하는 이유는 무엇입니까?
이 작동하지 않습니다
capturePreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:captureSession];
[self setCaptureView:[[NSView alloc] initWithFrame:[[self view] bounds]]];
// I know the order here is important and I think this is right
[[self captureView] setLayer:capturePreviewLayer];
[[self captureView] setWantsLayer:YES];
[[self view] addSubview:[self captureView] positioned:NSWindowBelow relativeTo:[self overlayView]];
[captureSession startRunning];
하지만 난 수 있도록 OverlayView 대신 해당 뷰에 형제의 자식, 그래서, 기본보기에 capturePreviewLayer 퍼팅한다는 것을 발견 일 :
capturePreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:captureSession];
[[self view] setLayer:capturePreviewLayer];
[[self view] setWantsLayer:YES];
[captureSession startRunning];
이유가 무엇입니까? 심지어 iOS에서 UIView를 사용하여 매우 유사한 작업을 수행했으며 이와 같이 이상한 것을 보지 못했습니다.
예, 그냥 추가 : [[self overlayView] setWantsLayer : YES]; 예상대로 작동합니다. 그리고 디버그 모드에서 overlayView의 레이어 속성에 null CALayer 대신 "NSViewBackingLayer"가 표시됩니다. 감사! – bellkev