Xcode中的Quartz Composer屏幕保护程序

时间:2015-08-29 17:06:44

标签: xcode cocoa screensaver quartz-composer

我的目标是将Quartz Composer文件捆绑到Xcode中并构建.saver文件。我目前正在使用Xcode预制模板,但在使屏幕保护程序工作时遇到问题。我正在将.qtz文件导入项目并使用QCView在屏幕上呈现它,但是当我测试构建的.saver文件时,我看到的只是一个黑屏。

- (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
    self = [super initWithFrame:frame isPreview:isPreview];
    if (self) {
        [self setAnimationTimeInterval:1/30.0];

        NSRect viewBounds = [self bounds];

        //create the quartz composition view
        qcView = [[QCView alloc] initWithFrame: NSMakeRect(0, 0, viewBounds.size.width, viewBounds.size.height)];
        //make sure it resizes with the screensaver view
        [qcView setAutoresizingMask:(NSViewWidthSizable|NSViewHeightSizable)];

        //match its frame rate to your screensaver
        [qcView setMaxRenderingFrameRate:30.0f];

        //get the location of the quartz composition from the bundle
        NSString* compositionPath = [[NSBundle mainBundle] pathForResource:@"QuartzComposerFileName" ofType:@"qtz"];
        //load the composition
        [qcView loadCompositionFromFile:compositionPath];


        //add the quartz composition view
        [self addSubview:qcView];

    }
    return self;
}

1 个答案:

答案 0 :(得分:0)

我尝试使用Xcode 6.4做同样的事情,看起来QCView不能使用Xcode 6.4。我在视图中放置了一个图像,并将QCView的大小设置为小于框架。我看到子视图的黑盒子但它永远不会呈现。即使是最基本的QC组合也是如此。

您可以通过使用QCRenderer自己渲染合成来使其工作。我在尝试之前放弃了,但这里是文档:https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/QuartzFramework/Classes/QCRenderer_Class/

相关问题