I want to optimize my app for iPhone 6 and iPhone 6+
But I have a launch screen size problem.
I created a simple project, and AppDelegate's code is:
#import "AppDelegate.h"
#import "ViewControllerOne.h" //xib screen size is 4 inch.
#import "ViewControllerTwo.h" // xib screen size is 4.7 inch.
#import "ViewControllerThree.h" // xib screen size is 5.5 inch.
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if ([UIScreen mainScreen].bounds.size.height == 568.0) {//4 inch
ViewControllerOne *first = [[ViewControllerOne alloc]init];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:first];
self.window.rootViewController = navigation;
}
else if ([UIScreen mainScreen].bounds.size.height == 667.0){//4.7inch
ViewControllerTwo * second = [[ViewControllerTwo alloc]init];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:second];
self.window.rootViewController = navigation;
}
else if ([UIScreen mainScreen].bounds.size.height == 736.0){//5.5inch
ViewControllerThree *third = [[ViewControllerThree alloc]init];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:third];
self.window.rootViewController = navigation;
}
}
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
#end
When I run iPhone 6 or iPhone 6+ simulator, it always appears 4inch screen when I run this project.(I included three launch image(Default-667h#2x.png, Default-736#3x.png, Default-568#2x.png) also.
What I have to do to resolve this problem.
I checked others question that similar to mine, and used their code, but all of those not works. That is maybe my technical skills relatively row.
Once you specify the images in Assets Catalog you will see the right images
Go to YourAppTarget> General> App Icons and Launch Images> Launch Image Source > Use asset Catalog
and then drag the appropriate size for each device.
In addition to adding images you can also add a Launch Screen File. This is a .XIB file that allows you to specify constraints in addition of launch images. It only works on iOS8. To support iPhone 6 and 6+, we only add this file and specify constraints:
To set the Launch Screen File add it to your project:
File > New > User Interface > Launch Screen
Then go to: YourAppTarget > General > App Icons and Launch Image s> Launch Screen File > Set your newly created image
You will still need launch images for Retina 4" and 3.5", if you are supporting iOS 7.
Related
my project runs without storyboards, so im loading my view inside AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
self.window.rootViewController = [[SYLoginController alloc] init];
[self.window makeKeyAndVisible];
return YES;
}
It used to work on iPhone 6 sim 9.3 but now, on all simulators it only shows a black screen. But on my iPhone 6 Device it works. Whereas on another iPhone 6 it also shows a black screen. Those two iPhones are literally the same 16gb iPhone 6 bought at nearly the same time.
In SYLoginControllers viewDiDLoad I'm logging the text of one of the buttons. Only on my device it prints the text, on all simulators and the other iPhone it prints (null), so i assume that the xib is not properly loaded.
SYLoginController is a UIViewController, and the related xib holds a UIView with its FilesOwner set to SYLoginController. I really can't see why it only works on this particular device. Also i tried [[SYTabBarController alloc] initWithNibName:#"SYLoginController" bundle:nil], this also does not work...
Did you tried to wrap it arround a Navigation Controller?
SYLoginController *syVC = [[SYLoginController alloc]initWithNibName:#"SYLoginController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] syVC];
self.window.rootViewController = nav;
Also check again if Custom Class is set to SYLoginController in the XIB-File. And the View is connected to the Files Owner.
[EDIT]
I restarted the iPad and it fixed the issue. I'm leaving it here because stack overflow discouraged deleting the question
I have a weird thing happening on iPad Air 2. Using the method mentioned in https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/UsingExternalDisplay/UsingExternalDisplay.html
I create a new UIWindow object for the secondary display connected through AirPlay.
- (void)checkForExistingScreenAndInitializeIfPresent {
if ([[UIScreen screens] count] > 1)
{
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = secondScreen.bounds;
self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.secondWindow.screen = secondScreen;
NSLog(#"Show external window");
// Set up initial content to display...
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Test" bundle:[NSBundle mainBundle]];
UIViewController *controller = [storyboard instantiateInitialViewController];
self.secondWindow.rootViewController = controller;
// Show the window.
self.secondWindow.hidden = NO;
}
}
When I run this code on an iPhone 5s, The code works perfectly and the secondary window is initialized. However, when I run this code from Xcode on the iPad Air 2, I only see a black screen. If the app is not run through Xcode, the app launches on the iPad but on the AirPlay display it only shows the home screen with the app icon highlighted. The audio is still routed through AirPlay.
Any help would be greatly appreciated.
Normally we change our UIWindow Color like this:
[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor myColor];
You can set your self.secondWindow color as:
secondWindow.backgroundColor = [UIColor whiteColor];
This was a ridiculous case and the solution to it was just as ridiculous. I restarted the iPad and the issue went away.
I'm creating an app without Storyboard on XCode 6.4 and when I run the app, no matter which simulator I use, I always get a (320,480) screen.
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
Ref img: http://i.stack.imgur.com/hGHmt.png
Already tryed:
vc.view.autoresizingMask =
UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
What should I do to make it fill the whole screen?
I had the same problem, You should set launch image of your app about default-568#2x.png with 640 x 1136 pixel size.
More info --> link
Also setting #2x #3x image assest will be good for you.
Add launch screen. It will be solved.
https://developer.apple.com/library/ios/recipes/xcode_help-image_catalog-1.0/chapters/AddingLaunchImagestoanAssetCatalog.html
I have created 5 extra Storyboards and I have deleted the main storyboard. This is because I would like to have 5 separate storyboards for the iPhone and iPad to match 5 different screen sizes. So far I have one for the iPhone 3.5 inch, one for the iPhone 4 inch, one for the iPhone 4.7 inch, one for the iPhone 5.5 inch and one for the iPad. I have put the code bellow in to link it all up and make it work. However, it doesn't work when you try and build the project. There is no errors but lets say I go into the iPhone 3.5 inch storyboard and I add a UIViewController and a Button or label, then when you build the project it goes to your launch screen and then it doesn't do anything from there. I have put the starting arrow in at the UIViewController but I cannot get anything to come up apart from the launch screen. I have tried this on all the storyboards and their simulators. I am wondering if I have missed something out in the code but I am not sure.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = nil;
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPad) {
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_iPad" bundle:nil];//iPad
} else {
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if (screenSize.height == 480){
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_iPhone4S" bundle:nil];//iPhone 3.5inch
} else
if (screenSize.height == 568){
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_iPhone5/5C/5S" bundle:nil];//iPhone 4inch
}
else
{ if (screenSize.height == 667){
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_iPhone6" bundle:nil];//iPhone 4.7inch
} else
if (screenSize.height == 736){
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_iPhone6Plus" bundle:nil];//iPhone 5.5inch
} else
//default storyboard
storyboard = [UIStoryboard storyboardWithName:#"Main.Storyboard" bundle:nil];
}
}
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
Find your info.plist file in your project and remove the line called "Main storyboard file base name".
Also, you forgot to create the window (credits to rdelmar).
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
I strongly advise you to look into Auto Layout and Size Classes. Using these two, you can support all screen sizes within one single Storyboard. It's a bit hard to get in the beginning, but it'll definitely be worth it in the long run.
There's a video about this from the most recent WWDC called Building Adaptive Apps with UIKit.
Possible duplicate:
How to make xib compatible with both iphone 5 and iphone 4 devices
Can I use two xibs with one viewcontroller - re: porting to iPhone 5
I have developed an iPhone app which now I'm trying to update giving it iPad and iPhone5 support.
I now there are lots of posts talking about how to handle this but none of them are working for me. 3.5'' iPhones and iPads load the xib they need but 4'' iPhone doesn't (although in simulator works fine), so here is how I handle it:
First of all I create three different xib files for each viewController (ViewController.xib, ViewController~ipad.xib and ViewController-568.xib). In the 4'' xib one I set the size of the view as "Retina 4 Full Screen".
Then I have used this to load the appropiate xib. It also may be relevant to say that in the AppDelegate I set the didFinishLaunchingWithOptions like this:
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSString *nibName = [UIViewController nibNamedForDevice:#"ViewController"];
self.viewController = [[BPViewController alloc] initWithNibName:nibName bundle:nil];
UINavigationController *navCont = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navCont;
[self.window makeKeyAndVisible];
self.viewController.navigationController.navigationBar.barStyle = UIBarStyleBlack;
return YES;
}
As I said it works like a charm in the simulator but in real device only iPad's and 3.5'' xib are load properly. The iPhone5 still is showing the up and down black bar...
You appear to be using the wrong suffix on your nibs/assets, use -568h#2x instead of -568h.
Alternatively i always switch various iOS assets / positions in code using:
if([ [ UIScreen mainScreen ] bounds ].size.height == 568 )
{
//iPhone 5.0 specific code
}
else
{
//None iphone 5 code
}
Its also worth noting at this stage that using more nib files to do this will result in a bigger .IPA. So its worth reading up on how autolayout works and going for that approach to keep executable size down.