Tuesday, June 14, 2011

Splash screen with animation for iPhone

Hello ppl,
I was doing this stuff for a friend and came across this thing... so thought to share.. might be it can help you if u too are looking out for the same.

The Default.png file that automatically gets displayed while your application is loading is a nice way to give the user some feedback (instead of looking at a black screen for a little while). With the iPhone 3Gs this might not be such a big deal, but in any case when loading is complete, the Default.png goes away instantly and you merely snap into your application's view. It works well enough, but it's not very sexy.

I've seen where some will take their default view and snapshot that and bring it into Photoshop, and lay down a semi-transparent black on top of it to make it look disabled. Thus you snap into the view in a less jarring manner. This is a little better, but it's still not sexy.

Why not use animation? Place a UIImageView over everything and when we're done launching, remove it with a fade and some zoom? Sure... and here is some quick code to do just that:

In your YourAppDelegate.h create a reference to a UIImageView and also whip up a method you'll call through code:
@interface YourAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
YourAppViewController *viewController;
UIImageView *splashView;
}
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;
Now, in YourAppDelegate.m add the guts of that method and some additional code in your applicationDidFinishLaunching:
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[splashView removeFromSuperview];
[splashView release];
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {

[window addSubview:viewController.view];
[window makeKeyAndVisible];

// Make this interesting.
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:@"Default.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
splashView.alpha = 0.0;
splashView.frame = CGRectMake(-60, -85, 440, 635);
[UIView commitAnimations];
}
You're done. You could mess with this in other ways, but it makes the whole entry into your application a lot more appealing in my opinion

Friday, June 10, 2011

Converting NSString to int and Vice Versa

int to NSString

The following example displays an integer's value as a text label:
currentScoreLabel.text = [NSString stringWithFormat:@"%d", currentScore];


NSString to int

The following example displays a text value as a integer:
int currentScore=[currentScoreLabel.text intValue];

Animate series of images

As iPhone does not supports gif files so heres the way to animate series of images

NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image1.png"],
[UIImage imageNamed:@"image2.png"],
[UIImage imageNamed:@"image3.png"],
[UIImage imageNamed:@"image4.gif"],
nil];

UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25; // seconds
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release];

For Getting Log

In Xcode, click Run > Console to see NSLog statements.
NSLog(@"log: %@ ", myString);
NSLog(@"log: %f ", myFloat);
NSLog(@"log: %i ", myInt);

Followers