Mac OS 开发

Mac 开发 自己制作屏幕保护程序

2019-09-26  本文已影响0人  隐身人

偶然 一次 看到 黑客 攻击的演示视频,顿时感觉好酷啊,这才是程序员,才是我辈楷模呀...
我也想这样...
但是技术不达标哇,
不过,这并不能影响我,
毕竟人不装逼跟咸鱼有什么区别.
所以就写了一个装逼的屏幕保护程序。

效果

git demo 下载地址

下面步骤:
1.创建一个 screensaver project
2.添加 GIF 图片到项目 并显示
3.添加到 系统偏好设置 - 桌面与屏幕保护程序中

创建1 创建2
//
//  BugView.m
//  Bug
//
//  Created by Smile on 2019/9/20.
//  Copyright © 2019年 Mac. All rights reserved.
//

#import "BugView.h"
@interface BugView ()

@property (nonatomic, strong) NSImageView *fImageView;
@property (nonatomic, assign) CGFloat angle;

@end

@implementation BugView

- (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
    self = [super initWithFrame:frame isPreview:isPreview];
    if (self) {
        [self setAnimationTimeInterval:1/30.0];
        
        NSBundle *bundle = [NSBundle bundleWithIdentifier:@"demo.Bug"];
        NSLog(@"bundle.bundlePath: %@",bundle.bundlePath);
        
        CGRect rect = self.bounds;
        CGRect fRect = CGRectMake(0, 0, rect.size.width, rect.size.height);
        
        NSString *fPath = [bundle pathForResource:@"x1" ofType:@"gif"];
        NSImage *floatImage = [[NSImage alloc] initWithContentsOfFile:fPath];
        
        _fImageView = [[NSImageView alloc] initWithFrame:fRect];
        _fImageView.image = floatImage;
        _fImageView.imageScaling = NSImageScaleProportionallyUpOrDown;
        _fImageView.animates = YES;
        _fImageView.canDrawSubviewsIntoLayer = YES;
        [self addSubview:_fImageView];
        
    }
    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

添加 gif图片进去,然后编译项目。


编译 找到屏幕保护程序 安装到系统列表

然后就 ok 开始装逼。

装逼效果,嘿嘿

git demo 下载地址

上一篇 下一篇

猜你喜欢

热点阅读