macOS开发,如何设置动态桌面壁纸(动态壁纸酷)

1.首先要先建立一个全屏的窗口

 1 //获取窗口控制器
 2 NSStoryboard *storyboard = [NSStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
 3 WallpaperWindowController *wwc = [storyboard instantiateControllerWithIdentifier:@"AboutWindowController"];
 4 
 5 //获取当前所有屏幕,你可能有多个显示器
 6 NSArray(NSScreen * ) * screens = [NSScreen screens];
 7 
 8 //设置为全屏窗口
 9 CGRect rect = CGRectMake(screen.frame.origin.x, screen.frame.origin.y, screen.frame.size.width, screen.frame.size.height);
10 [self.window setFrame:rect display:YES animate:NO];
11 [self.window makeKeyAndOrderFront:nil];

2.设置窗口层级

1 //设置与桌面同级别
2 [self.window setLevel:kCGDesktopWindowLevel];

3.设置跟随工作空间显示

1 [self.window setCollectionBehavior:(NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorStationary | NSWindowCollectionBehaviorIgnoresCycle)];

 

 

posted @ 2024-05-16 19:38  如此的完美和无懈可击  阅读(82)  评论(0编辑  收藏  举报