2011-11-30 35 views
1

我试图在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一些代码:嵌入石英组成?如果是这样,我需要输入什么?

在此先感谢

回答

2

你只需要创建一个QCView实例,并把它作为您的屏幕视图的子视图:

.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 
+0

完美。谢谢:D – Josh

+0

这不适用于Xcode 6.4。子视图被创建,但构图从不渲染器。 我考虑使用QCRenderer来显式渲染组合,但放弃了:https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/QuartzFramework/Classes/QCRenderer_Class/ –