I am trying to create an application where movies are played in NSViews that may move behind other views. I want to use AVFoundation so I will be rendering video to an AVPlayerLayer.
However, video is always played on top of everything else, and this seems to be an issue with the layers within views.
Consider the following, within a view create:
NSView *backView = [[NSImageView alloc] init];
NSImage *image = [[NSImage alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"Background" withExtension:@"png"]];
[backView setImage:image];
[self addSubview:backView];
NSView *layerView = [[NSView alloc] initWithFrame:CGRectMake(0, 0, 100, 500)];
[layerView setWantsLayer:YES];
[layerView.layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
[self addSubview:layerView];
NSView *frontView = [[NSImageView alloc] init];
image = [[NSImage alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"Foreground" withExtension:@"png"]];
[frontView setImage:image];
[self addSubview:frontView];
Looking at this you will get a white layer rendered on top of everything else. On top of that the white layer won't be affected by the alpha property of the parent view.
Am I making a naive mistake here - I seem to be doing everything as recommended.
Thank you!
Chances are that you're getting some strangeness when working with the combination of overlapped layer-backed views and non-layer-backed. I would try making the other two layer-backed views.