Wednesday, January 16, 2013

Two Splash Screen display in iphone

In this application we will see how to applied two splash screen in the iPhone. So let see how it will work.

Step 1: Open the Xcode, Create a new project using Window Base application. Give the application “TwoSplashScreen”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: We need to add three UIViewController in the class in the project. So select the project -> New File -> Cocoa Touch ->ViewController class and give the class name “SplashScreen”,”FirstView” and “SecondView”.

Step 4: We need to add two image in the Resource folder.

Step 5: Open the TwoSplashScreenAppDelegate.h file and make the following changes in the file.

#import <UIKit/UIKit.h>
@class SplashScreen;

@interface TwoSplashScreenAppDelegate : NSObject <UIApplicationDelegate> {
   
     SplashScreen *splashScreen;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
 @property (nonatomic, retain) IBOutlet SplashScreen *splashScreen;

@end

Step 6: Double click the MainWindow.xib file open it to the Interface Builder. First drag the “Image View” from the library and place it to the window. Select the window and bring up attribute inspector and select the “logo.png”. Now save it, close it and go back to the Xcode.

Step 7: In the TwoSplashScreenAppDelegate.m file make the following changes:

#import "TwoSplashScreenAppDelegate.h"
#import "SplashScreen.h"

@implementation TwoSplashScreenAppDelegate

@synthesize window=_window,splashScreen;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
       
    splashScreen = [[SplashScreen alloc]
                    initWithNibName:@"SplashScreen"
                    bundle:nil];
    [_window addSubview:splashScreen.view];
   
    [splashScreen displayScreen];

   
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
   
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
   
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
   
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
   
}

- (void)applicationWillTerminate:(UIApplication *)application
{
   
}

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

@end

Step 8: Open the SplashScreen.h file and make the following changes in the file:

#import <UIKit/UIKit.h>

@interface SplashScreen : UIViewController {
   
    IBOutlet UIImageView *displaySplash;
    UITabBarController *tabBarControlller;

}

 @property (nonatomic, retain) IBOutlet UITabBarController *tabBarControlller;

 @property (nonatomic, retain) IBOutlet IBOutlet UIImageView *displaySplash;

-(void)displayScreen;
-(void)removeScreen;

@end

Step 9: Double click the SplashScreen.xib file and open it to the Interface Builder. First drag the “Image View” from the library and place it to the window. Select the window and bring up attribute inspector and select the “screen.png”.Connect File’s Owner icon to the Image View and select displaySplash. Drag the TabBarController from the library in the interface builder. First select the first tab from the TabBarController and bring up Identity Inspector and select “FirstView” class. Do the same thing for the Second Tab and select “SecondView”.Now save it, close it and go back to the Xcode.

Step 10: In the SplashScreen.m file make the following changes:

#import "SplashScreen.h"

@implementation SplashScreen
@synthesize displaySplash,tabBarControlller;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

-(void)displayScreen
{
   
    [NSThread sleepForTimeInterval:0.02];
    [self performSelector:@selector(removeScreen) withObject:nil afterDelay:16.0];
   
}

-(void)removeScreen
{
       
    [self.view addSubview:tabBarControlller.view];
   
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn’t have a superview.
    [super didReceiveMemoryWarning];
   
    // Release any cached data, images, etc that aren’t in use.
}

#pragma mark – View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

Step 11: Now double click the FirstView.xib file and open it to the Interface Builder. Select the View and bring up Attribute Inspector and change the background color. Now save the it , close it and go back to the Xcode.

Step 12: Double click the SecondView.xib file and open it to the Interface Builder. Select the View and bring up Attribute Inspector and change the background color. Now save the it , close it and go back to the Xcode.

Step 13: Now compile and run the application in the Simulator.

You can Download Source Code from here TwoSplashScreen


Source : edumobile[dot]org

0 comments:

Post a Comment