0

我对 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

非常感谢任何形式的帮助!

4

1 回答 1

1

如果layer是 nil,你应该首先怀疑它的 parentplayerView是 nil。是吗?如果是这样,您可能还没有在笔尖上连接插座。(我看到您已在代码中声明 playerView为插座,但这并不意味着您已正确配置笔尖。)

于 2013-04-17T21:07:21.757 回答