简体   繁体   English

OSX Cocoa应用程序中的启动画面

[英]Splash screen in OSX Cocoa app

I'm working on a Cocoa app in Xcode. 我正在使用Xcode开发可可应用程序。

I would like to create a splash screen using a .png file as the image content in the splash screen. 我想使用.png文件作为初始屏幕中的图像内容来创建初始屏幕。

I've accomplished the following: 我已经完成以下工作:

  • The splash screen is displayed for 2 seconds when the app is launched 启动应用程序时,启动屏幕显示2秒钟
  • The splash screen is displayed at the center of the screen 初始屏幕显示在屏幕中央
  • The splash screen can't be minimized, moved or re-sized by the user 用户无法最小化启动屏幕,移动屏幕或调整其大小

From my class: 从我班上:

IBOutlet NSView *customView;
IBOutlet NSImageView *splashScreen;
IBOutlet NSWindow *splashWindow;

Here's what I have so far in awakeFromNib 这是我到目前为止awakeFromNib的内容

NSRect rect = NSMakeRect(0,0,421,231);
splashScreen = [[NSImageView alloc] initWithFrame:rect];
[splashScreen setImageScaling:NSScaleToFit];
[splashScreen setImage:[NSImage imageNamed:@"splash.png"]];
[customView addSubview:splashScreen];

CGFloat xPos = NSWidth([[splashWindow screen] frame])/2 - NSWidth([splashWindow frame])/2;
CGFloat yPos = NSHeight([[splashWindow screen] frame])/2 - NSHeight([splashWindow frame])/2;
[splashWindow setFrame:NSMakeRect(xPos, yPos, NSWidth([splashWindow frame]), NSHeight([splashWindow frame])) display:YES];

And then in applicationDidFinishLaunching: 然后在applicationDidFinishLaunching中:

sleep(2); /* Yeah. I know this is bad. No need to comment on that */
[splashWindow close];

Questions: 问题:

  1. How do I bring the splash image to the front of every open window on the desktop? 如何将启动画面带到桌面上每个打开的窗口的前面?

  2. The PNG is a rectangle but the tiny areas near the corners of the image should be transparent. PNG是一个矩形,但是靠近图像角落的微小区域应该是透明的。 However...the transparent spots just shows as white..How do I fix that? 但是...透明点只是显示为白色。如何解决?

  3. How do I implement the feature where the image is closed if the user clicks on the image before it's closed automatically? 如果用户在自动关闭图像之前单击该图像,该如何实现关闭图像的功能?

  4. How do I set up a timer to close the window after 2-3 seconds? 如何设置计时器以在2-3秒后关闭窗口? (NSTimer) (的NSTimer)

for: 对于:

  1. use zwindow level property of NSWindow and make the splash window floating 使用zwindow level property of NSWindow并使初始窗口浮动

  2. make the window non opaque (requires a borderless window) so google for a tutorial on how to make such a window type 使窗口变为不透明(需要无边界窗口),因此,谷歌提供了有关如何制作此类窗口类型的教程

  3. AND 4. sleep is actually preventing the things. AND 4.睡眠实际上阻止了事物的发展。 for 3 you'd need a mouseDown on the image, for 4 a timer ==> both are events. 对于3,您需要在图像上单击mouseDown,对于4,则计时器==>都是事件。 events are NOT dispatched when you sleep the main thread. 休眠主线程时不会调度事件。 The NSRunLoop must be running. NSRunLoop必须正在运行。 One way would be too have a NSRunloop runUntilDate call instead of the sleep 一种方法是调用NSRunloop runUntilDate而不是睡眠

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM