我对 AVFoundation 和 QuartzCore 开发非常陌生,我在使用 CALayers 时遇到了麻烦。如果这是一个愚蠢的问题,我很抱歉。
这是我的代码:
。H
#import <Cocoa/Cocoa.h>
#import <AVFoundation/AVFoundation.h>
#import <QuartzCore/QuartzCore.h>
@interface Document : NSPersistentDocument 
{
    AVPlayer *player;
    AVPlayerLayer *playerLayer;
    NSView *playerView;
}
@property AVPlayerLayer *playerLayer;
@property AVPlayer *player;
@property IBOutlet NSView *playerView;
@end
.m
#import "Document.h"
@implementation Document
@synthesize playerView;
@synthesize player;
@synthesize playerLayer;
- (id)init
{
    self = [super init];
    if (self) {    
    }
    return self;
}
- (NSString *)windowNibName
{
    return @"Document";
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
    [super windowControllerDidLoadNib:aController];
    [[aController window] setMovableByWindowBackground:YES];
    // HERE the layer is nill, and I don't understand why it's not getting initialized?! 
    [[[self playerView] layer] setBackgroundColor:CGColorGetConstantColor(kCGColorBlack)];
}
+ (BOOL)autosavesInPlace
{
    return YES;
}
@end
非常感谢任何形式的帮助!