How to do transparent the launch image slowly.(alpha = 0.0;) - iphone

I can see the launch image(png at the root of the project, sized:320x480 pixels)  on the iPhone simulator and iPhone device.
And then,I want to do transparent it(the launch image) slowly .(alpha = 0.0;)
But I cannot do it.though I tried variously.
 
 
Thank you,
  Katsumi

Take a look at UIView animation methods. Method like animateWithDuartion should be sufficient for your goal. Your fade-out animation in the simplest implementation will looks like following:
[UIView animateWithDuration:1 animations:^(void){self.splashImage.alpha = 0.0f;}];

When the app launches you'll have to immediately create a new instance of the image via UIImageView and throw it on the main window. Then once you get access to that UIView you can use basic animation techniques to fade it out, such as -animateWithDuration:animations:.
Of course you'll want to setup some type of view below this, so you have your main app's content available right away.
Code sample:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// PLACE YOUR APP LAUNCH CODE HERE
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default"]];
[self.window addSubview:imageView];
[imageView release];
[UIView animateWithDuration:2.0 animations:^{
imageView.alpha = 0.0;
[imageView removeFromSuperview];
}];
return YES;
}

Related

Fade out Launch Image on 4 Inch iPhone screen

On launch, I am fading from my launch image to the application's interface. To achieve this, I am adding a UIImageView with "Default.png" and animating its alpha just before makeKeyAndVisible.
Should Default.png always return the device-specific (or resolution-specific) version of the launch image? Or should I be checking the screen's bounds and scale to pick the right one for the retina vs non-retina and 3.5 vs 4 inch screens?
I expected Default.png to behave much like other image resources - use the #2x version when supported (and the -568h version on the iPhone 5). But my experimentation in the simulator leads me to believe otherwise. Running the 4 inch simulator, the 3.5 inch image is used. This results in a splash image that does not extend to the bottom of the screen. The screenshot below shows the transition mid-animation.
Unfortunately I don't have each device so was unable to confirm if this is just a quirk of the simulator.
In short, I want to be sure that the retina image is used on retina devices, and the 4 inch image is used on 4 inch devices.
This is my code
- (BOOL) application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[self.window makeKeyAndVisible];
[self _startLaunchAnimation];
return YES;
}
- (void)_launchAnimation {
CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
UIImageView *launchImageView = (UIImageView*)[self.window viewWithTag:1000];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone
forView:self.window
cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(startupAnimationDone:finished:context:)];
[launchImageView setAlpha:0.0];
[launchImageView setFrame:CGRectMake(-60.0f, 0.0f, 320.0f, screenHeight)];
[UIView commitAnimations];
}
- (void)_startLaunchAnimation {
CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
NSString *imageName = nil;
if (screenHeight == 568.0f) {
imageName = #"Default-568h.png";
} else {
imageName = #"Default.png";
}
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *launchImageView = [[UIImageView alloc] initWithImage:image];
[launchImageView setTag:1000];
[self.window addSubview:launchImageView];
[NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:#selector(_launchAnimation)
userInfo:nil
repeats:NO];
}
For the record, this is my version of #agassi_yzh's solution:
//fade from the launch image to the interface
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
NSString *imageFile = (screenHeight == 568.0f) ? #"Default-568h.png" : #"Default.png";
UIImageView *splash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageFile]];
[self.window.rootViewController.view addSubview:splash];
[UIView animateWithDuration:0.5
animations:^{
splash.alpha = 0;
}
completion:^(BOOL finished) {
[splash removeFromSuperview];
}
];
//display the main window
[self.window makeKeyAndVisible];
The answer is you will have to explicitly load the device specific version of the image. This is custom animation and you cannot rely on Apple's Default whatever loading behavior to achieve what you want.
First make sure that you you are configured properly and the correct default load image is displayed on the devices (dont trust the simulator too much (aka I never even use the simulator its so buggy))
And then as previous commenters suggested load a view with your images.
Remember that the default image is going to be loaded and shown by the cocoa framework. All you can do is show a view afterward, if you try and do some of the admittedly clever hacks with the on load that are on the web you will find that they will always break in some way.
If you need a full screen image animated or not on iPhone 5 you need to load that image explicitly for the device thats all there is to it.
Yes, you provide Default.png and Default#2x.png, you even have to supply Default-568h#2x.png for the iPhone 5 4" screen.
You app will use standard, retina or big retina according to device but note that Apple discourage using the Default launch image as any intro animation sequence.
The trick you could use is to add an image view as the first screen of the app when it's launched and immediately fade it out, this will give the user the impression that the launch image is fading out even though the launch image is gone, and it's your image view taking over.
Look at the Launch image section of the Apple Custom Icon and Image Creation Guidelines:
Supply a launch image to improve user experience.
Avoid using your launch image as an opportunity to provide:
• An “app entry experience,” such as a splash screen
• An About window
• Branding elements, unless they are a static part of your app’s first
screen Because users are likely to switch among apps frequently, you
should make every effort to cut launch time to a minimum, and you
should design a launch image that downplays the experience rather than
drawing attention to it.

After launching app, how to fade in from Default.png?

When launching an iOS application, the screen jumps from the Default.png into the interface. For a current project, I'd like to fade in from that Default.png into the app's interface. Is there a good way to do this?
I took a bit of rooster117 and runmad's answers, and this is what I came up with.
Add a UIImageView to the first UIViewController's properties:
#interface DDViewController : UIViewController {
...
UIImageView *coverImageView;
}
...
#property (nonatomic, retain) UIImageView *coverImageView;
Then, for the "home screen" of the iPad app, I call the following:
- (void)viewDidLoad
{
[super viewDidLoad];
...
coverImageView = [[UIImageView alloc] init];
}
-(void)viewWillAppear:(BOOL)animated {
UIImage *defaultImage;
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
NSLog(#"Landscape!");
defaultImage = [UIImage imageNamed:#"Default-Landscape.png"];
} else {
NSLog(#"Portrait!");
defaultImage = [UIImage imageNamed:#"Default-Portrait.png"];
}
coverImageView = [[UIImageView alloc] initWithImage:defaultImage];
[self.view addSubview:coverImageView];
}
-(void)viewDidAppear:(BOOL)animated {
//Remove the coverview with an animation
[UIView animateWithDuration:1.0f animations:^(void) {
[self.coverImageView setAlpha:0.0];
} completion:^(BOOL finished){
[coverImageView removeFromSuperview];
}];
}
Yeah this isn't that hard to do. I accomplish this by making an image view with the default image and just animating it out. Something like this (put in the viewDidLoad of the first view controller):
_coverImage = [UIImage imageNamed:#"Default.png"];
}
[self.view addSubview:_coverImage];
[UIView beginAnimations:#"FadeOutCover" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(removeAndDeleteCover)];
[_coverImage setAlpha:0.0f];
[UIView commitAnimations];
then implement removeAndDeleteCover and do:
[_coverImage removeFromSuperview];
Hope that helps and if you need it to work for the iPad as a universal app you will have to check for that case and add the right default image.
Someone made a control for it on cocoacontrols.com
Here is the link for it: http://cocoacontrols.com/platforms/ios/controls/launchimagetransition
Expanding on rooster117's answer, you'll want to properly load your final "landing place", that is the view controller you want the user to actually interact with, before dismissing the "splash screen" view controller. This is very important for apps that load data from the network.
I seem to have done this in ios7 this way, think it should also work with 6 ?
https://stackoverflow.com/a/19377199/1734878

Smooth transition from launch image to main view

Is it possible to implement a smooth transition when the app loads, from the launch image to the first view?
The default behavior is on/off, with an immediate change: the launch image appears, then it instantaneously disappears to let the main view controller take place. I'd like to implement some fading or zooming in or out.
Is this possible?
Thank you!
There's no framework support, but you can get that result if you do it yourself, manually. Depending on what your launch image is, and what your UI looks like, you can do it in different ways, but basically: make your first view controller load and display your default.png image in an image view when it loads up. Then animate a fade out of that image to reveal your actual UI.
Modified Dancreek's answer to do it all in AppDelegate application:didFinishLaunchingWithOptions. I like this because the code is guaranteed to only run at app start, and it's not polluting any of the view controllers.
It's very simple:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// set up your root view and stuff....
//.....(do whatever else you need to do)...
// show the main window, overlay with splash screen + alpha dissolve...
UIImageView *splashScreen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default.png"]];
[self.window addSubview:splashScreen];
[self.window makeKeyAndVisible];
[UIView animateWithDuration:0.3 animations:^{splashScreen.alpha = 0.0;}
completion:(void (^)(BOOL)) ^{
[splashScreen removeFromSuperview];
}
];
}
You are in luck. I just did this a few min ago. You need a splash screen. An image on your view that is exactly the same as your default image that the device loads. Then in your app have it dismiss with a fade animation called from the viewDidAppear function
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelector:#selector(killSplashScreen) withObject:nil afterDelay:1.0];
}
- (void)killSplashScreen {
[UIView animateWithDuration:0.5 animations:^{splashScreen.alpha = 0.0;} completion:NULL];
}
We often use something called "splashView" to do this. It was written by Shannon Applecline and available under the CC license. You will have to do some Googling to find it.
//
// splashView.h
// version 1.1
//
// Created by Shannon Appelcline on 5/22/09.
// Copyright 2009 Skotos Tech Inc.
//
// Licensed Under Creative Commons Attribution 3.0:
// http://creativecommons.org/licenses/by/3.0/
// You may freely use this class, provided that you maintain these attribute comments
//
// Visit our iPhone blog: http://iphoneinaction.manning.com
//

How do I make an up to down animation when I click the add (plus) button on the iPhone?

How do I make a top to down or down to top animation when I click the add (plus) button on the iPhone?
If you are looking for the "Built In" API, Alex is correct. And that works perfectly well.
If you are looking to understand how do make your own animations, you have several options in Core Animation
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html
but a great starting point is simply the UIView animateWithDuration
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html
you should also get to know the CGAffineTransform
putting this all together, here is an example of sliding a view onto screen from the bottom right, having it fade in at the same time. (I dont really know a situation where I would want to do that, but its an example).
I put this in the app delegate so its easy to simply "paste" into a new project. Normally you would not put any views of this nature directly into the window.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UIWindow *w = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];;
self.window = w; //property defined in the .h file
[w release];
UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
v.backgroundColor = [UIColor redColor];
v.center=self.window.center;
v.alpha=0;
[self.window addSubview:v];
//if you ran the code to here, you would see a square in the center of the window.
//now lets move the square off (off screen) with a transform and then animate it back (on screen)
CGAffineTransform t = CGAffineTransformMakeTranslation(160+50, 240+50); //place the view just off screen, bottom right
v.transform=t;
//if you ran the code to here, you wouldnt see anything as the squre is placed just off screen, bottomr right
[UIView animateWithDuration:.5 //make the animation last .5 seconds
delay:.3 //wait .3 seconds before performing the animation
options:UIViewAnimationOptionCurveEaseOut //slow down as it reaches its destination
animations:^
{
v.transform=CGAffineTransformIdentity; //reset any transformation
v.alpha=1.0; //fade it in
}
completion:^(BOOL finished){} //nothing to do when it completes
];
[self.window makeKeyAndVisible];
return YES;
}
I think you're thinking of presentModalViewController; you can use it to present a new screen that slides up from the bottom of the screen.

iPhone-SDK:Activity Indicator during Startup?

I am having a Default.png file in my project, so that whenever my app launches Default.png file loads there. As my app is retrieving data from server at startup(app launch), i want to show activity indicator as well while Default.png file is loading. Is it possible to activate both the process at a time, i mean showing Default.png and enable activity indicator at a time during startup?
But i tried putting Activity Indicator code in 'applicationDidFinishLaunching' but it doesn't show activity indicator at the time of showing Default.png file. But i am sure that Activity code what i have, is working fine on other screens. Problem is only during app launch.
Can someone share your ideas please?
thanks.
Clave/
You can't do any animation in the Default.png image. You should replace it as soon as possible with a view/controller (containing the activity indicator). Than after showing that controller, load your data and possibly an other controller (in a thread).
What i do in my app is immediately load an imageview with the Default.png image covering the screen. then you can add a progress indicator on top of the imageview while you do your server work on a background thread.
You should always avoid net activity in the applicationDidLaunch method as this method has a timeout after which, if it does not return, Apple will kill your app. this is important because say the user is on edge and the server trip takes 30 seconds - your app will appear to have crashed to the user.
By doing the net work in a background thread and returning applicationDidLaunch, you will keep apple from killing your app, you will be able to let the user use the app before the new data comes in (if you want) and your app will appear to launch faster.
You should always avoid net activity in the applicationDidLaunch method as this method has a timeout after which, if it does not return, Apple will kill your app. this is important because say the user is on edge and the server trip takes 30 seconds - your app will appear to have crashed to the user.
So you think that I should not put XMLPraser on the applicationDidLaunch?
NSURL *url = [[NSURL alloc] initWithString:#"http://sites.google.com/site/iphonesdktutorials/xml/Books.xml"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
That's how it works:
(Made on Xcode version 4.2.1)
So...
In the AppDelegate.h add this:
#property (nonatomic, strong) UIImageView *splashView;
In the AppDelegate.m add this:
On the top of the page of cours #synthesize splashView;
And then:
- (void) splashFade
{
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 setAnimationDelay:2.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(startupAnimationDone:finished:context:)];
splashView.alpha = 0.0;
[UIView commitAnimations];
//Create and add the Activity Indicator to splashView
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.alpha = 1.0;
activityIndicator.center = CGPointMake(160, 360);
activityIndicator.hidesWhenStopped = NO;
[splashView addSubview:activityIndicator];
[activityIndicator startAnimating];
}
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[splashView removeFromSuperview];
}
The [UIView setAnimationDelay:2.5] is responsible for how long the splashView will be in front by the delay time you choose.
You can change the position of the indicator by changing the nubmers of x/y in:
activityIndicator.center = CGPointMake(160, 360);
At last, under the methode:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Just add this:
[self performSelector:#selector(splashFade) withObject:nil];
And there you go :)
Hope it helped.
Have a nice programming....