Adding a splash screen to my project - iphone

I have created a project which consist of a tabbarcontroller and a navigationcontroller.
The first view or the first tab is a tableview controller. Now i need to add a splashscreen to my application, so when the app loads it will show a welcome screen and then land on the tableviewcontroller.
My workings so far;
This is added in my viewDidLoad method.
myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"splash.jpg"]];
myImageView.frame = [[self view] frame];
[self.view addSubview:myImageView];
[self.view bringSubviewToFront:self.myImageView];
The problem is that the splash screen or the UIImageView loads inside the tabbarController/NavigationController, and it does not take the full width and length of the screen. What should i do to fix this programatically ?

In application bundle you need to copy the splash screen images with the name "Default.png" and "Default#2x.png" for Retina. The app will load this automatically, you don't need to do more work.
Here you have a link for this: http://iosdevelopertips.com/cocoa/defaultpng-the-secret-of-the-load-screen.html

Add the images that you want to use to the resources of your project and name them Default.png and Default#2x.png (if you are providing it for a retina screen). Be sure no name them exactly. If you get the capitalisation wrong, it will work in the Simulator (which is not case-sensitive), but not on the device (which is case-sensitive).
Be aware that a "splash screen" is discouraged by the Apple Human Interface Guidelines:

Have you given the Launch Images a look in your target settings?

You would probably want to add the splash screen in the app delegate's didFinishLaunchingWithOptions method. Then start an animation of fade out (or whatever animation you need). Finally removing the splash screen view when the animation is complete.

You have to add the UIImageView to the root's view:
UIView *rootView = [[[[UIApplication sharedApplication] delegate] viewController] view];
[myImageView setFrame:rootView.bounds];
[rootView addSubview:myImageView];

you can use the uiimage view to add an array of images to play an animation, try the following
code in
-(void)viewDidAppear:(BOOL)animated {
animationSplashImageView.animationImages = imageArray;
animationSplashImageView.animationDuration = 5;
animationSplashImageView.animationRepeatCount = 1;
[animationSplashImageView startAnimating];
}
IBOutlet UIImageView* animationSplashImageView;
was defined in the main view of your app.
also you could test your splash using tool Splashx Free, which is on Apple App Store: http://itunes.apple.com/cn/app/splashx-free/id500137095?mt=8

Related

First view appears as black?

I have a program where I'm working with user authentication and alert views. the problem is quite strange. Every other time I launch the application, the first view appears as normal, and then black, and then back to normal, and so on and so forth.
Launched once:
Launched twice:
Here's the storyboard:
Functionally, it's both the same, but I have no idea what could be causing this problem!
Addition:
The alert is called on viewdidappear.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self presentAlertViewForPassword];
}
Addition 2 (build settings) (simulator is iphone 4):
Where do you have the AlertView show method? I think this could be because when you press the home button while you are at the UITableViewController and then you launch the app. This is where it starts from.
Do you have the login AlertView code in your applicationDidFinishLaunch?
This black screen seems your alert's view screen. You can set its background image. Do one thing
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIImageView *iV = [[UIImageView alloc] initWithFrame:self.view.bounds];
iV.image = [UIImage imageWithNamed:#"imageNameHere"];
[self.view addSubView:iV];
[self presentAlertViewForPassword];
}
Set that Christmas Keeper image on view's background. Hope it helps. Also check your splash screen's image. Search default.png in search box of xcode may be this is different or may be there is two default.png. Just a guess :)
Edit after notice your comment: the launch image is basically a uiimageview on the first page with an image in my directory
So I think that black screen is your launch image because it appears before appearing the first view of your app. You didn't set it yet. Please include a default.png image into your project and it should be same as your first View's `imageView' image.

iOS: is it possible to attechment of MFMailComposeViewController with Animation?

I am working on attach images into MFMailComposeViewController everything is fine working but i want to know that is it Possible to give animation of Attachment?
For Ex:- When we attach images from Photo Gallery in iPhone Device. and while select mail Button that all selected Images Move's in MailComposeViewcontroller with Nice ANIMATION.
So please can any-buddy guide me this stuff is possible or not.? and if YES then how can i set Animation of Attachment.
There exists some semi-solution. You can in fact add any UIView as subview of you main app's window. It will than sit on top of all apps content. Using this you can simulate animation of attaching image to MailComposeViewcontroller
See my example code. This code slides image view from top of the screen to mail composer so it imitates adding of image as attachment. Everything is commented.
// Get apps main window
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
// Setup frames of animated image view in apps window - adjust to your needs
CGRect finalImageFrame = CGRectMake(30, 220, window.frame.size.width-60, 100);
CGRect initialImageFrame = finalImageFrame;
initialImageFrame.origin.y = -initialImageFrame.size.height;
// Create image view to be animated as attachment
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myImage"]];
imageView.frame = initialImageFrame;
imageView.backgroundColor = [UIColor redColor];
// Add animated image view to window
[window addSubview:imageView];
// Animate image view with slide in from top
[UIView animateWithDuration:0.4
animations:^{
imageView.frame = finalImageFrame;
}];
// Present mail composer
[self presentViewController:mailComposer animated:YES completion:^{
// Once the controller appears, hide the image view - adjust this animation according to you needs
[UIView animateWithDuration:0.4
animations:^{
imageView.alpha = 0;
} completion:^(BOOL finished) {
[imageView removeFromSuperview];
}];
}];
Of course the code may need some adjustments and polishing, but it shows the concept. You can play with animations to make some better effect. There is a lot of animation tweaks I would add, but I wanted to keep the example code as short at it can be ;-)
That is iOS custom animation effects and is not exposed as iOS API's so no you cannot get this effect out of box. The reason I know that this effect is not exposed to developers is from Apple iOS 6 Docs. There is only one method which deals with animate and its the standard one.
What you can try is this. After the user has selected image(s) from his photo gallery (i.e. from ALAssetsLibrary) you can animate a "image" that looks like a MFMailComposeViewController. The animation would similar to what iOS provides i.e. background fading, MFMailComposeViewController appearing and the images sitting in the "body" section of the mail. Once the animation finishes, remove the "image" of MFMailComposeViewController and show the actual call MFMailComposeViewController invoked with animaiton:FALSE option. Hope I was clear. Essentially what you are providing is an illusion of MFMailComposeViewController and once animation is done, taking away the illusion and showing the reality.
Theoretically this could work but exact animation timing and user perceived feel has to be tested out.

IOS - Load a sub-controller/view into a View

I'm working on an iPad app (actually, converting a iPhone app into iPad app). Since I can put two "Iphone screens" on one "iPad screen" (just regarding the space), I have my iPad view 50% occupied by my original view (loaded through my main controller).
(so far so good)
Now, on the remaining 50% of the iPad view, I want to include another View (for which I have a controller and a view, iphone-sized). I tried to add a "View" component, but how do I load another controller into it ? is that even possible ?
MainViewController loading MyView1.xib
I want to load, in the "View" component, MySecondaryController, loading MyView2.xib
http://imageshack.us/photo/my-images/835/d8fs.png/
Thanks
you can do it something like below...write below code in function which is in Mainviewcontroller(for example on some button tap)
yoursecondviewcontroller *objDate = [[yoursecondviewcontroller alloc] initWithNibName:#"yoursecondviewcontroller" bundle:nil];
objDate.delegate = self;
UIPopoverController *datePopOver = [[UIPopoverController alloc] initWithContentViewController:objDate];
datePopOver.delegate = self;
[datePopOver setPopoverContentSize:CGSizeMake(320,393)];//give any size you want.
[datePopOver presentPopoverFromRect:CGRectMake(50,700, 320, 393) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];//give size and origin whatever you want in FromRect .....
You can also define UIPopoverController object in .h file....
and don't forget to set delegate of UIPopoverController that is UIPopoverControllerDelegate
Let me know it is working or not!!!
Happy Coding!!!!

How can I display a introduction modal view when the app start up?

I have a tab bar application and I want to display those views that most part of apps have, with the name of the company or the name of the app.
I've created the follow viewController
Introduction *introducao = [[Introduction alloc] initWithNibName:#"Introduction" bundle:nil];
I don't know where exactly should I insert the code to show the modal because I have a tab bar application:
[self.navigationController presentModalViewController:galeria animated:YES];
I've tried to insert these lines on appDelegate.. but didn't work.. somebody have an idea?
if you are trying to show a splash screen right when the application opens, you should use a Default.png image instead of a view controller showing an image. Check out the Apple Documentation on Human Interface Guidelines and Beginning iPhone Development.
First of all, you'll need to ensure that you have a navigation controller present to present the model view from. Otherwise in the above code you'll be messaging nil and nothing will happen. Then you'll want to put the presentModalViewController:animated: call in your app delegate's applicationDidFinishLaunching: implementation.
Thanks for all answers.. they were very useful to understand better the process..
I have found a solution that does exactly what I need! So if someone need to create those splash screens with a sequence of images it is very useful:
Just create a ImageView on the Delegates Header and do the following:
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:#"Default.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
to control the duration of the splash screen:
[self performSelector:#selector(removeSplash) withObject:nil afterDelay:1.5];
To remove the splash:
-(void)removeSplash;
{
[splashView removeFromSuperview];
[splashView release];
}
so If you want to create a sequence of image just create a method to change the splashView.image.. and create a NSTIMER to call it..

How do I detect orientation on app launch for splash screen animation on iPad!

Hi I have an app and I have two *.pngs for default splash screen:
Default-Landscape.png
Default-Portrait.png
What I want is to animate this default splash screen away when my app is loaded and ready to go.
To achieve this I would normally present an UIImageView with either default-landscape or default-portrait (depending on the device orientation), keep it on screen for a certain time and then animate it away.
My problem is that if I call [[UIDevice currentDevice] orientation] in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
The answer is always that the device is in portrait orientation even if I clearly have it in landscape. I tried this in simulator and on the device as well and the behaviour is the same.
Does anyone know a fix for this or maybe some other approach?
Thanks!
I had troubles with this and I solved it by making one image 1024x1024 and setting the contentMode of the UIImageView to UIViewContentModeTop, then using left and right margin autoresizing. So long as your portrait and landscape default images are the same layout then this will work fine.
Just to clarify here's what I used:
bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:SplashImage]];
bgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
bgView.contentMode = UIViewContentModeTop;
To get around this problem I installed the splash image view inside of a view controller that allowed both orientations. Even though the device reported the wrong orientation at startup, the view controller seems to get the right one.
You can use UIApplication statusBarOrientation as follows:
if ( UIDeviceOrientationIsLandscape( [[UIApplication sharedApplication] statusBarOrientation] ))
{
// landscape code
}
else
{
// portrait code
}
Maybe you could show a blank view with black background at start time and place [[UIDevice currentDevice] orientation] into this view's viewDidAppear and start your splash screen from there?
Another solution would be to read the accelerometer data and determine the orientation yourself.
To know at start what is the orientation (UIDevice orientation don't work until user have rotate the device) intercept shouldAutorotateToInterfaceOrientation of your View Controller, it is called at start, and you know your device orientation.
There are certainly times when you want to transition from the loading image to something else before the user gets control of your app. Unless your app is really simple, going from loading image to landing page probably won't be sufficient without making the app experience really suck. If you ever develop a large app, you'll definitely want to do that to show progress during setup, loading xibs, etc. If an app takes several seconds to prepare with no feedback, users will hate it. IMO, there's nothing wrong with a nice transition effect either. Almost nobody uses loading screens the way Apple suggests to. I don't know which apps you looked at that showed the "empty UI" type loading screens they suggest. Heck, even Apple doesn't do that except in their sample code and none of my clients would find that acceptable. It's a lame design.
Only the first view added to the window is rotated by the OS. So if you want your splash screen to automatically rotate AND your main view is rotatable then just add it as a child of that view.
Here is my code for fading out the appropriate splash screen image:
// Determine which launch image file
NSString * launchImageName = #"Default.png";
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
launchImageName = #"Default-Portrait.png";
} else {
launchImageName = #"Default-Landscape.png";
}
}
// Create a fade out effect
UIImageView* whiteoutView = [[[UIImageView alloc] initWithFrame:self.window.frame] autorelease];
whiteoutView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
whiteoutView.autoresizesSubviews = YES;
whiteoutView.image = [UIImage imageNamed:launchImageName];
[[[self.window subviews] objectAtIndex:0] addSubview:whiteoutView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
whiteoutView.alpha = 0.0;
[UIView commitAnimations];
Note: You'll have to update it to support hi-res screens.
It sounds like you're not using the launch image the way Apple recommends in the iOS HIG. It specifically calls out that you should not use it as a splash screen, but rather as a skeleton version of your actual UI. The net effect is that your app appears to be ready just that much faster.
The suggestions that you could draw a splash screen yourself after the app has launching in viewDidAppear or similar also are missing the basic purpose of a launch image. It's not a splash screen. If your app is ready, let the user interact with it, don't waste their time drawing a splash screen.
From my five minute survey of Apple apps and third-party apps, everyone showed a portrait launch image, loaded the portrait version of the UI, and then rotated to landscape. It's been a while since programming on iOS, but I think this mirrors the order of the method calls -- first your app gets launched, then it is told to rotate to a particular orientation.
It might be a nice enhancement request to file with Apple though :)