Apple approve multiple storyboard instead of Size class? - ios

I have a project with complex design, so i prefer to use different storyboard according to size of the iPhone device, will apple approve it ?
Is any restriction to force to use auto layout?
How can i use minimum storyboard to achieve this task without using auto layout and size class?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// int screenHeight = [UIScreen mainScreen].bounds.size.height;
// NSLog(#"Screen Height is %i", screenHeight);
// grab correct storyboard depending on screen height
UIStoryboard *storyboard = [self grabStoryboard];
// display storyboard
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
- (UIStoryboard *)grabStoryboard {
// determine screen size
int screenHeight = [UIScreen mainScreen].bounds.size.height;
UIStoryboard *storyboard;
switch (screenHeight) {
// iPhone 4s
case 480:
storyboard = [UIStoryboard storyboardWithName:#"Main-4s" bundle:nil];
break;
// iPhone 5s
case 568:
storyboard = [UIStoryboard storyboardWithName:#"Main-5s" bundle:nil];
break;
// iPhone 6
case 667:
storyboard = [UIStoryboard storyboardWithName:#"Main-6" bundle:nil];
break;
// iPhone 6 Plus
case 736:
storyboard = [UIStoryboard storyboardWithName:#"Main-6-Plus" bundle:nil];
break;
default:
// it's an iPad
storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
break;
}
return storyboard;
}

Short answer
Yes
Yes, Apple will approve the app.
However I would suggest using 1 storyboard instead of multiple storyboards.
Cons of using multiple storyboards are
It take 200% more time than actual time. Think tomorrow when you will have more iPhones.
It makes app size more bigger
Worst part is it take more time for compile while working on the project & take more time when switching storyboards.
The most bad thing is it have more chances of missing some changes in some storyboard.

YES! Apple will accept your app.
To help you factorize your design, you can use storyboard references to reuse storyboard parts common to every device.
http://code.tutsplus.com/tutorials/ios-9-staying-organized-with-storyboard-references--cms-24226
(Only available from iOS 9)

yes definitely apple will approve it, I have used it in one of my apps. But it may increase the memory consumption.

Related

I need to set a separate Main Interface for iPhone and iPad, but Xcode only lets me set one interface for the project when it is universal

I am unable to set a specific Main interface for iPad, even though my app is universal. Xcode used to have separate tabs for the Deployment Info on iPhone and iPad but now they are they same. However my game is radically different on iPhone and iPad and I need to set separate storyboards for each interface.
Someone please help if you know the solution.
you could set the value in the Deployment Info -> Main Interface to an empty string and implement a custom logic in your AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard *initialStoryboard;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
initialStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
} else {
initialStoryboard = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:nil];
}
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [initialStoryboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
You need to use size classes for this. To select the correct size class, open your storyboard file, then click on this icon towards the bottom of the screen.
Clicking wAny hAny will allow you to change the size class type and set specific constraints for the different device types. You can read more information about size classes here

UISplitViewController on universal app with Storyboard

I'm want to make an app that uses a UISplitViewControler on the iPad (as far as I understand it's only available on the iPad) but I want the app to be universal.
The setup is like this:
I have a UITableView (as a master view) and when I select a row it should display a detail view of that cell. I am using a Storyboard and I can't figure out how to implement the split view only for the iPad.
What would be the easiest way to achieve that? Thanks.
You don't need two storyboards to do this.You can use them both in a single storyboard.For iphone ,we normally use a class SWRevealViewController(if you are new to iOS coding ..:)) for side menu and splitviewcontroller for ipad.We can also use SWRevealViewController for ipad as well.It depends on your requirement.
For universal apps,create viewcontrollers using size Classes(usually we use any height any width for universal apps ).
change these size classes and create different viewcontrollers for ipad and iphones as required.In most cases any height any width will do the job.
After creating the viewcontrollers,in the appdelegate ,using the instantiateViewcontrollerWithIdentifier method, load the required viewcontroller.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The device is an iPad running ios 3.2 or later.
}
else {
// The device is an iPhone or iPod touch.
}
For ipad load the splitviewcontroller. and swrevealviewcontroller for iPhone.
This is the core basics.If you need any more information,let me know.
EDIT
Have you seen an arrowmark ath the initial VC(viewcontroller) in the storyboard?This vc is loaded first after the launch screen.In my app,I have a home screen which is common to both iphone and ipad(using size classes as mentioned above).So I can set this vc as the initial VC.In this case I don't have to do anything in the appdelegate.But if I have a different home screen for ipad,then I can make a condition check in the appdelegate didFinishLaunchingWithOptions
You can load the First screen like this.You should follow through splitVC tutorilal and swrevealcontroller tutorial to set the side menu.You should load the SWrevealVC or splitViewcontroller only if the first screen contains the side menu.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UISplitViewController *split = [storyboard instantiateViewControllerWithIdentifier:#"SplitViewController"];
[AppDelegate setRootController:split storyboard:storyboard actiontype:0];
}
else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *split = [storyboard instantiateViewControllerWithIdentifier:#"SWrevealVC"];
[AppDelegate setRootController:split storyboard:storyboard actiontype:-1];
}
return YES;
}
+(void)setRootController:(UIViewController*)controller
storyboard:(UIStoryboard*)storyboard actiontype:(int) actiontype;
{
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && actiontype == 0)
{
UISplitViewController *splitViewController = (UISplitViewController *)controller;
//splitViewController.presentsWithGesture = false;
UINavigationController *masterNavigationController = [splitViewController.viewControllers objectAtIndex:0];
SideMenuViewController *controller = (SideMenuViewController *)masterNavigationController.topViewController;
controller.splitViewController = splitViewController;
splitViewController.delegate = (id)controller;
}
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[UIView
transitionWithView:appDelegate.window
duration:0.5
options:UIViewAnimationOptionAllowAnimatedContent
animations:^(void) {
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
appDelegate.window.rootViewController = controller;
[UIView setAnimationsEnabled:oldState];
}
completion:nil];
}
The code may look lengthy,but take it simple.You can only understand the logic if u do things.

iPhone Image sizes [duplicate]

This question already has answers here:
IOS 8 image scaling and auto layout
(3 answers)
Closed 7 years ago.
I'm current running the iPhone 6 simulator in my project.
I know with different iPhones you need different resolution settings.
If I want to develop for the iPhone 4, 5, 6 and 6+. In my situation, what should be the sizes for 4, 5 and 6+. I think I don't need to change 6 because I'm using it as my base.
(If you could, please add iPad to list)
If someone could in direct me to how iOS automatically selects the right image resolution according to what device they have.
Any questions just comment!
I did this in Objective-C a while ago, so forgive me if it's different for Swift.
You have to make a different .storyboard file for each image resolution, and then in your AppDelegate.m you add a some code like:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *iPhone4storyBoard = [UIStoryboard storyboardWithName:#"storyboard4" bundle:[NSBundle mainBundle]];
// Device is an iPhone 5 or 5S
UIStoryboard *iPhone5storyBoard = [UIStoryboard storyboardWithName:#"storyboard5" bundle:[NSBundle mainBundle]];
// And so on...
if ([UIScreen mainScreen].bounds.size.height == 568.0) {
self.window.rootViewController = [iPhone5storyBoard instantiateInitialViewController];
} else if (/* test for other devices here */){
self.window.rootViewController = [iPhone6storyBoard instantiateInitialViewController];
}
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
return YES:
}
Which checks for device resolution, and applies the relevant storyboard.
Also, a suggestion for resizing images: Use Prepo.
Prepo automatically resizes app icons and splash screens to the desired values.

"Application windows are expected..." error when loading storyboard for Ipad

I'm loading different storyboards for Iphone and Ipad and the Iphone's storyboards load good but when I start the Ipad Simulator I got the "Application windows are expected..." error.
this is the code in AppDelegate:
#implementation AppDelegate
- (UIStoryboard *)grabStoryboard {
UIStoryboard *storyboard;
// detect the height of our screen
int height = [UIScreen mainScreen].bounds.size.height;
if (height == 480) {
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_Iphone3" bundle:nil];
// NSLog(#"Device has a 3.5inch Display.");
}
if (height >= 1024 && height <= 2048 ) {
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_Ipad" bundle:nil];
NSLog(#"Device has a 4inch Display.");
}
else {
storyboard = [UIStoryboard storyboardWithName:#"Storyboard_Iphone4Up" bundle:nil];
// NSLog(#"Device has a 4inch Display.");
}
return storyboard;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [self grabStoryboard];
// show the storyboard
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
In the console I see the NSLog message but the storyboard doesn't load and the "Application windows..." error appears.
I'm using some Scroll Views and some elements but i thinkg those are not the problem because there is an option for them "Adjust Scroll View Insets".
I uploaded some screen shots to show more about my project. Thanks for your time.
I figured it out. When you copy all stuff from the Iphone storyboard to the Ipad one the Initial View Controller checkbox is unchecked. Just check it and all will be good (:

Using multiple Storyboards in Xcode

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.

Resources