xcode - cocoa 屏幕保护程序嵌入 quartz

标签 xcode macos cocoa quartz-graphics screensaver

我正在尝试在 Xcode 中创建一个屏幕保护程序以部署为 .saver 文件。

但是,我想将 Quartz Composition 文件 (QTZ) 嵌入其中。

屏保模板中没有XIB或NIB,如何在代码中嵌入qtz?

这是 ScreenSaverView.h 中的内容:

#import <ScreenSaver/ScreenSaver.h>
@interface XmasView : ScreenSaverView
@end

在 ScreenSaverView.m 中,

#import "ScreenSaverView.h"

@implementation XmasView

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

- (void)startAnimation
{
    [super startAnimation];
}

- (void)stopAnimation
{
    [super stopAnimation];
}

- (void)drawRect:(NSRect)rect
{
    [super drawRect:rect];
}

- (void)animateOneFrame
{
    return;
}

- (BOOL)hasConfigureSheet
{
    return NO;
}

- (NSWindow*)configureSheet
{
    return nil;
}

@end

我想我必须在 initWithFrame: 中放入一些代码来嵌入 quartz 组合?如果是这样,我需要输入什么?

提前致谢

最佳答案

您只需创建一个 QCView 实例并将其放置为屏幕保护程序 View 的 subview :

.h:

#import <ScreenSaver/ScreenSaver.h>
#import <Quartz/Quartz.h>

@interface XmasView : ScreenSaverView
@property (strong) QCView* qtzView;
@end

.m:

#import "ScreenSaverView.h"

@implementation XmasView
@synthesize qtzView;

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

        //create the quartz composition view
        qtzView = [[QCView alloc] initWithFrame: NSMakeRect(0, 0, NSWidth(frame), NSHeight(frame))];
        //make sure it resizes with the screensaver view
        [qtzView setAutoresizingMask:(NSViewWidthSizable|NSViewHeightSizable)];

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

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

        //add the quartz composition view
        [self addSubview:qtzView];
    }
    return self;
}

//...implementation continues

关于xcode - cocoa 屏幕保护程序嵌入 quartz ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8327138/

相关文章:

iphone - CorePlot 1.0 + LLVM GCC 4.2 + ARC-如何?

iphone - 如何使用 UIWebView 加载一页又一页?

iOS - TableViewCell 中的并排标签对象

ios - 将 NSDate 转换为毫秒纪元时间

java - Android Studio 模拟器不会运行简单的 Hello World 应用程序

c++ - 存档问题不是 C 中链接的体系结构 (x86_64)

java - 无法在macOS Sierra上启动Eclipse Neon

cocoa - 获取WebView的总滚动大小(HTML内容的大小)

cocoa - 避免 "[superclass] may not respond to [selector]"警告,而不会引发 LLVM 的 "Cannot cast ' super'"错误

cocoa - 使用核心数据(Mac OS X cocoa)对_有序_项目列表进行建模的最佳方法是什么?