Заставка с какао Вставить кварц - PullRequest
1 голос
/ 30 ноября 2011

Я пытаюсь создать заставку в 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: чтобы встроить кварцевую композицию? Если так, что я должен был бы вставить?

Заранее спасибо

1 Ответ

2 голосов
/ 01 декабря 2011

Вам просто нужно создать экземпляр 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
...