我正在尝试在 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/