What type of project to create? and how to show a splash screen?

Discussion in 'iOS Programming' started by MythicFrost, Dec 15, 2009.

  1. MythicFrost macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #1
    I'd like to have my app do this for starters:
    Show a little basic splash screen picture for about 3 seconds, and then switch to the menu page, and then based on what the user chooses, IE "Play" or "Preferences", show the page I want.

    Would you do this by creating a view with the splash screen, and then a view with the menu buttons on it and then another view for each other thing and just swap views? or do I have the wrong idea for views?

    My normal thought process would be just showing and hiding controls but that might get a little messy.

    It kind of leads me into what project type do I make?
    Window-based Application or View-based Application?

    Thanks
     
  2. johnnyjibbs macrumors 68030

    johnnyjibbs

    Joined:
    Sep 18, 2003
    Location:
    London, UK
    #2
    Based on your aspirations, I would do the following:

    Start a Navigation-Based project (normally a good start) and designate the menu screen as your root view controller. Don't worry, we'll show the splash screen as a modal view controller on top of it at launch (with modalTransitionStyle set to crossdisolve so that it fades out).

    Then you can have a UITableView or a couple of buttons on your root view controller (menu) with your designed actions and each of these when pressed can push the desired screen onto the navigation stack.

    To create the splash screen, implement a BOOL isFirstLaunch in your app delegate and set to YES in the application did launch method of the app delegate. Then, in the viewDidLoad method of your root view controller, initialise and show (without animation) a modal view controller that will display your splash screen.

    e.g.
    Code:
    // Root view controller (menu) .m
    
    - (void)viewDidLoad {
    
        // Call super
        [super viewDidLoad];
    
        // Show splash screen if first load
        // (To be honest you could do away with the appDelegate flag but this method will be called again if you have a low memory situation)
        if (appDelegate.isFirstLaunch) {
            // Set first launch to NO so this doesn't get called until we relaunch app
            appDelegate.isFirstLaunch = NO;
            // Bring up modal view of splash screen immediately so it appears first
            SplashScreenViewController *ssvc = [[SplashScreenViewController alloc] initWithNibName:blah blah blah];
            [self presentModalViewController:ssvc animated:NO];
            [ssvc release];
        }
    
    }
    

    Set the modal transition style to crossdissolve so that it will fade out when it exits. Then stick whatever buttons or whatever you want on your splash screen or set up or have no user actions and get it to dismiss itself after 3 seconds or whatever in its view did appear method (you could use the perform selector after delay method to avoid the hassle of implementing a timer):

    e.g.
    Code:
    // Splash screen view controller .m
    
    - (void)viewDidAppear:(BOOL)animated {
    
        // Call super
        [super viewDidAppear:animated];
    
        // Dismiss after 3 seconds
        [self performSelector(dismissSplashScreen) withObject:nil afterDelay:3.0]
    
    }
    
    
    - (void)dismissSplashScreen {
        // Dismiss splash screen
        self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self dismissModalViewControllerAnimated:YES];
    }
    
    I reckon that would get you roughly to where you're going. The splash screen would look neat if you set it to show a full screen UIImageView that displays the same picture as your Default.png pic, so that the splash screen goes on directly from startup.

    In fact, you don't need the splash screen to be a modal view controller at all - you could just display a UIImageView on top of the main view with this image by adding it as a subview of the navigation controller and then adjusting its alpha from 1.0 to 0.0 (using animation). That would probably be simpler.
     
  3. MythicFrost thread starter macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #3
    Hi thanks for your reply!

    I'm trying to do what you said but am having issues. I'm using a View-based project (I made it before you replied, and I don't like the look of the navigation-based ones).

    • I tried typing appDelegate and it says it doesn't know what it is? I tried doing: MyGameAppDelegate.isFirstLaunch but the property isFirstLaunch isn't there.
    • It also doesn't know what a SplashScreenViewController is.
    • I'm curious, how do I make a variable that I can access anywhere, a global variable? I tried doing something else and declaring UIImageView *ivView; near the top of MyGameViewController.m, when I try and use it in multiple functions it doesn't list it's properties?

    I'm hoping once I find how to fix these I'll be able to continue. Thanks.
     
  4. csnplt macrumors 6502

    csnplt

    Joined:
    Aug 29, 2008
    Location:
    Chicago Area
    #4
    For a simple splash screen, I use default.PNG. It's much easier than doing it through code: All you need to do is design a splash screen PNG, name it Default.png, and place it in your app's root directory, and it will show at app launch. You can then sleep the main thread for 3 seconds or so to keep the splash screen up, or not.

    Technically, this isn't the intended use for Default.png (meant to provide the illusion of a faster app launch by showing a default screenshot), but I've always used it with no problems.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    If you're looking at that code and asking these questions, I think it's time for you to step back from the real coding and go learn the basics of Objective-C and iPhone Development.
     
  6. icewing macrumors 6502

    Joined:
    Jun 19, 2008
    Location:
    St Louis
    #6
    + 1 - I was thinking the same when reading this thread.
     
  7. MythicFrost thread starter macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #7
    Thanks, how do I sleep the main thread?
    Your probably right, but I'd still rather just know why it's not working.
    If I had to guess I'd say I need to import a namespace or something for SplashScreenViewController to work.

    I've got no idea about appDelegate, I tried using MyGameAppDelegate but the option isFirstLaunch wasn't there.
    And I'm still unsure about a global variable, I can declare it but it won't list it's properties when I'm trying to use it until I've set it in a function.
     
  8. amorya macrumors 6502

    Joined:
    Jun 17, 2007
    #8
    It won't be that, objective-c doesn't support namespaces.
     
  9. MythicFrost thread starter macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #9
    Good to know :D

    Anyone know the answers to any of those questions?
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    I do. But since you don't seem to understand the basics of Objective-C, you probably won't understand my answers either. Sorry.

    Here's some things to educate yourself about, though:
    • Learn the difference between an instance variable and a class reference, especially when referring to them in code.
    • Learn how to use #import statements, especially when referring to classes that are defined in other files.
    • Search this forum for tips and techniques on how to share values between classes.
     
  11. MythicFrost thread starter macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #11
    Thanks for your reply, I think I know how to use #import statements except for the part about referring to classes defined in other files, but I'll learn it when I come to it.
    Haven't done #1 and #3 yet but I might later, what's a class reference? is it declaring a variable from a class? if that makes sense.

    I've had some success though, I looked over johhnyjibbs code again and realised what I was doing wrong.
    I created a new UIViewController SubClass (File->New File->Etc..), named it SplashScreenViewController, and I've duplicated the code and it runs but with one minor change. (I also left out the appDelegate code.)

    In MyGameViewController.m:
    Code:
    - (void)viewDidLoad {
    	[super viewDidLoad];
    	SplashScreenViewController *ssvcController = [[SplashScreenViewController alloc] init];
    	[self presentModalViewController:(ssvcController) animated:NO];
    	[ssvcController release];
    }
    I just used init instead of initWithNibName, and in SplashScreenViewController:
    Code:
    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView {
    	UIImageView *ivView = [[UIImageView alloc] initWithImage:([UIImage imageNamed:(@"Default.png")])];
    	[[self view] addSubView:(ivView)]; //I get a warning on this line, saying it may not respond to addSubView.
    }
    I was hoping I could do that, add the UIImageView to the view and have it display the picture. It's not working though.
    Rest of the code from SplashScreenViewController:
    Code:
    - (void)viewDidAppear:(BOOL)animated {
    	[super viewDidAppear:(BOOL)animated];
    	[self performSelector:@selector(dismissSplashScreen) withObject:nil afterDelay:3.0];
    }
    
    - (void)dismissSplashScreen {
    	self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    	[self dismissModalViewControllerAnimated:(BOOL)YES];
    }
    I'm not sure why it's not working, any help is appreciated, thanks.
    (PS, still wondering what to do so I can use appDelegate? I've tried using MyGameAppDelegate but it doesn't have the isFirstLaunch property)
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    So, MyGameViewController.m is no longer complaining about not knowing what SplashScreenViewController is (a reference to a class defined in another file, by the way)? As for learning #import when you come to it, you're already at that point.

    Also,
    Don't forget that method names are case-sensitive.
     
  13. MythicFrost thread starter macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #13
    Ok I get the reference to a class in another file thing now. I meant when I have something I need to import I'll learn then, I don't know of anything that needs importing atm.
    Changed addSubView to addSubview, thank you!

    I'm still not seeing the Default.png image load, I see the blue screen (from my image Default.png automatically being shown) but then it turns grey quickly, I still must be doing something wrong.

    (PS, although I sort of know, could anyone tell me the proper definition of what a method is? would addSubView be a method?)
    Thanks :D
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    Seriously, step away from the Xcode with your hands up and lay down in front of an Objective-C book.
     
  15. MythicFrost thread starter macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #15
    Ahah that made me laugh :)

    C'mon someone tell me what a method is! lol.
     

Share This Page