0
我想創建一個應用程序,其中電影在NSView中播放,可能會移動到其他視圖後面。我想使用AVFoundation,所以我將渲染視頻到AVPlayerLayer。做層支持的NSView打破視圖層次?
但是,視頻始終在所有其他視頻上播放,這似乎是視圖中的圖層存在的問題。
考慮下面的,在一個視圖中創建:
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];
望着這你會得到呈現在一切之上的白色層。 最重要的是,白色圖層不會受到父視圖的alpha屬性的影響。
我在這裏犯了一個天真的錯誤 - 我似乎正在做一切建議。
謝謝!
使用重疊的支持層的視圖和非支持層的組合時,您可能會遇到一些奇怪的情況。你有沒有嘗試製作其他兩層支持? – gaige
謝謝你蓋格。這看起來確實有用。調整窗口大小時,仍然會出現一些圖層彈出,但總的來說,排序按預期工作。你想添加上面的答案嗎? – Giles
很高興聽到它。我添加了答案。謝謝。 – gaige