2
votes

I'm working on a Cocoa app in Xcode.

I would like to create a splash screen using a .png file as the image content in the splash screen.

I've accomplished the following:

  • The splash screen is displayed for 2 seconds when the app is launched
  • 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

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:

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. 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? (NSTimer)

1
I really tried to answer it but there is a lot to explain here. it seems kinda broad to me ..Daij-Djan
btw some advice: don't -- see also stackoverflow.com/questions/685062/…Daij-Djan
I really tried to answer it but there is a lot to explain here. it seems kinda broad to me => I agree. That's why I didn't bother yesterday.El Tomato

1 Answers

4
votes

for:

  1. use zwindow level property of NSWindow and make the splash window floating

  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. for 3 you'd need a mouseDown on the image, for 4 a timer ==> both are events. events are NOT dispatched when you sleep the main thread. The NSRunLoop must be running. One way would be too have a NSRunloop runUntilDate call instead of the sleep