Made iPhone app with 4" dimensions, how to make universal? - ios

I've made an app for the iPhone, and everything has the iPhone5 4" dimensions.
The simulator runs the game fine, and it works great on my iPhone.
Now, I understand that in order to release the game on iPhone 3.5" screens and iPad, I must create files within the same project file.
I have:
Iphone4":
main.h
main.m
iphone4".storyboard
other.h
other.m
Iphone3.5":
main1.h
main1.m
iphone3.5".storyboard
other1.h
other1.m
Ipad:
main2.h
main2.m
ipad.storyboard
other2.h
other2.m
I have a number of questions:
How does the the downloaders device detect what folder to take
the game from?
When I run the simulator in 3.5", despite having created the app in 3.5" settings, it still sources the storyboard created in the 4" folder. However, when I run the iPad simulator it runs the storyboard in the iPad folder. So in short, how do I get Xcode to detect when it should use 4" dimensions in the simulator or when to use the 3.5" dimensions?
If I were to release the app on the App Store as a 4" game, will anyone that downloads it on an iPhone4 or older still be able to play it (i.e will it auto rescale?)
Happy to discuss further over Skype or other medium. Would be grateful for a quick response.
Kind regards,
Max

You are using Storyboards, so do this is your app delegate
- (UIStoryboard *)grabStoryboard {
UIStoryboard *storyboard;
// detect the height of our screen
int height = [UIScreen mainScreen].bounds.size.height;
if (height == 480) {
storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
// NSLog(#"Device has a 3.5inch Display.");
} else {
storyboard = [UIStoryboard storyboardWithName:#"MainRetina" bundle:nil];
// NSLog(#"Device has a 4inch Display.");
}
return storyboard;
}
then in your view did load add this:
UIStoryboard *storyboard = [self grabStoryboard];
and if you are using iPad add in the size for that and rename your storyboards to that effect

You do not have to, and should not, have different source files for the different platforms. It's quite straightforward to make the 3.5" and 4" iPhone/iPods run from the same storyboard.
You generally DO want a different storyboard for iPad and iPhone. The info tab in your project has spaces for both filenames, and at runtime, the app decides which one to load automatically.
The rules are changing with iOS 8 however. If this is a new app that's still under development, you might want to think about using the new adaptive UI functions built into iOS 8. Apple has pretty radically changed the way they expect us to handle this stuff, as well as the way we're supposed to handle device rotation (short answer: we're NOT supposed to handle rotation any more. Instead, we get notified about size changes in our views and we're supposed to respond to those. Now there are "size classes" that have states of "regular" and "compact" for each dimension, and you teach your app how to lay itself out in the different combinations of regular and compact sizes.
Apple has strongly hinted that new device sizes are coming, and that we should adopt the new way of doing things if we want to work correctly with the new devices. It's pretty likely that any new devices will only run iOS 8, and will depend on the new adaptive UI APIs for their UI layouts. I don't know what kind of compatibility they will have with older devices, but it will likely have limitations.

Related

Device Layout Does Not match Simulator or Storyboard

I've been away from Xcode for a while, so I may have missed changes in the latest couple of releases. The layout of views looks identical in the Storyboard, and on the simulators (iPhone6 and iPhone7), but different on my iPhone 6. I have no warnings or errors in the Storyboard, and I am using Xcode 8. The device acts as if it had a shorter screen than the simulator -- things that are spread appropriately on the storyboard or simulator, are squeezed together vertically on my phone. What is the reason for this difference?
Have you assigned launch images with the correct dimensions for the different form factors? An easy way to verify this is to add a print statement in a view controller to see what the bounds are for the screen. Verify that these values match what you expect for the device.
The following from Apple documents this:
Because device screen sizes vary, launch screen sizes vary too. To
accommodate this, you can provide a launch screen as an Xcode
storyboard or as a set of static images for the devices your app
supports. Using an Xcode storyboard is the recommended approach, as
storyboards are flexible and adaptable.
While not an official Apple site, this link also references this as a potential issue:
The launch XIB or storyboard is required to support iPhone 6 sized
apps.
Another possibility is that you have the screen zoomed in on the device. To change this, go to Settings > Display & Brightness and select Display Zoom at the bottom. Ensure that you have Standard selected. If you are zoomed in, then the device will scale down (A 6 behaves like an SE, a Plus behaves like a 6/7).

Developing universal in Xcode 6

I have Xcode 6 beta installed and I'm trying to develop an universal app. Before Xcode 6, you had to create 2 separate Storyboards for iPad and iPhone and you could set it in the Deployment Info.
In Xcode 6, it seems that separation is gone. There aren't 2 tabs to set the storyboards individually.
But when you go to create a Storyboard, you are asked to choose a device family.
Can someone explain what's going on in Xcode 6 please?
Thank you.
To support the new Size Classes, you'll need to enable "Use Size Classes" in the File Inspector of your storyboard. This will allow you to configure your storyboard for multiple device sizes.
Note that this will make your storyboard incompatible with Xcode 5.
When you've enabled this, you'll see the size selector appear at the bottom of the screen. Use this to select your device size:
In your project preferences, you can still select a different storyboard for iPhone or iPad using the dropbown box. Notice that the storyboard name will persist if you select a different one for each device.
Even though this is still an option, Apple is moving developers towards a single, unified storyboard.
It seems Auto layout is used to support all devices now, yet you can create separate storyboards? Have you tried calling the separate storyboards in code in the app delegate
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//Use iPhone Storyboard
} else {
//Use iPad Storyboard
}
After Xcode 6 > version for using different storyboard for iPhone and iPad need to follow xcode-6-separate-storyboard-for-ipad-and-iphone
Note : For Application which does not use Auto Layout, so while adding new storyboard for iPad and disabling auto layout, a pop will appear that's where you need keep size class data to iPad as shown in below screen.

How/whether to make a universal storyboard in Xcode

When creating a storyboard file in Xcode, you must select if it is for iPhone or iPad. This implies one should always put iPhone and iPad UIs into separate storyboards. Is this true?
My app has multiple storyboards. While the Main.storyboard files largely differ between iPhone and iPad, other storyboards are nearly identical. The only difference might be segue being a push on iPhone vs popover on iPad, which can be handled programmatically. It seems awfully silly and redundant to make two storyboards.
So if making one "universal" storyboard, should iPhone or iPad be selected in Xcode? Does it matter?
As of Xcode 6, we can create a single unified storyboard for all the devices.
For more info - Documentation
iOS 8 makes dealing with screen size and orientation much more
versatile. It is easier than ever to create a single interface for
your app that works well on both iPad and iPhone, adjusting to
orientation changes and different screen sizes as needed. Design apps
with a common interface and then customize them for different size
classes. Adapt your user interface to the strengths of each form
factor. You no longer need to create a specific iPad storyboard;
instead target the appropriate size classes and tune your interface
for the best experience.
There are two types of size classes in iOS 8: regular and compact. A
regular size class denotes either a large amount of screen space, such
as on an iPad, or a commonly adopted paradigm that provides the
illusion of a large amount of screen space, such as scrolling on an
iPhone. Every device is defined by a size class, both vertically and
horizontally. iPad size classes shows the native size classes for the
iPad. With the amount of screen space available, the iPad has a
regular size class in the vertical and horizontal directions in both
portrait and landscape orientations.
Edit:
It only supports iOS 8(backward compatible applies only for iOS 7) and later.
You've got to create to separate storyboards for each kind of device. If you would delete the iPad storyboard, than your app would use the iPhone's one. You'll realize it when you'll see the 2x button at the bottom of the screen. Everything will be scaled to fit the larger screen - and the graphics would be really bad.
The only suitable workaround is to copy-paste everything from your iPhone Storyboard to iPad storyboard. Just follow the next steps:
Open iPhone.storyboard,
Press CMD+A,
Press CMD+C,
Switch to iPad.storyboard,
Press CMD+V,
You'll see, that all the screens, segues, properties and actions are transferred to your new storyboard. All that you have to do is to fix the frames of all your elements so that they'll suit new screen sizes.
And don't forget, that a good iPad application shouldn't be the same as the iPhone version. There are a lot of cool things which you can do with iPad!

Universal Storyboard?

In the old XIB world of iOS development, I was able to create one View Controller and one XIB, and use them for both the iPhone and iPad environments. With just a few code tweaks, the XIB would resize and adjust to fit the different dimensions and aspect ratios. This allowed me to reduce the risk of the two layouts getting out of sync over time.
Is the same thing possible in the world of Storyboards? By default Xcode creates two distinct storyboards for my Universal app -- one for the iPhone and one for the iPad.
How can I use one storyboard for both?
Thanks!
Updated:
Size Classes in Xcode 6 will essentially achieve the goal of Universal Storyboards. More info here:
https://developer.apple.com/library/prerelease/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_6_0.html
In short...you can't.
There's a workaroud I use to create the iPad storyboard at the end of the iPhone development.
You have to locate the iPhone story board and using the Terminal you can duplicate it giving it the name of the iPad storyboard that Xcode has created for you. Delete the empty old storyboard and open the newly copied one changinge the targetRuntime attribute to "iOS.CocoaTouch.iPad" instead of the old value "iOS.CocoaTouch".
Open the iPad storyboard with Xcode, everything is there but it still needs to be arranged and connected to the ViewController (wiring stuff included..). It's not perfect but I usually do it to save some error prone copy and paste (and several hours as well).
If you just want to target your app for iPhone and deliver it to iPad you can just use the iPhone Xib and you'll get the 2x little botton in your right corner.
Update late 2014 (after Xcode 6 beta release)
Xcode 6 now allows you to define a single storyboard and through the size classes concept, to make it adapt to all their devices. This solution is a bit confusing (especially if you're familiar with how this problem is solved in the Android environment) but it's something in the right direction IMHO.
Yes you can.
You can simply select the very same storyboard in Xcode under General/Deployment info
I have a few app which have that.
They share a lot of view controllers.
If you use freeform size than you can create separate view controller in the story board and two separate segues.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self performSegueWithIdentifier:#"Open VC" sender:sender];
} else {
[self performSegueWithIdentifier:#"Open VC iPad" sender:sender];
}
Only disadvantage is that you cannot use iPad specific controls directly from the storyboard (popover etc.) unless you switch to an iPad storyboard

converting story board from iphone to ipad

I have a storyboard for my iphone version of my app and I want to have the same storyboard for my ipad version (only bigger). My story board only has text and buttons is there anyway I can just convert the whole thing and increase the size by 2, or do have to resize everything manually?
You really need to do more than just resize you know. iPad users don't generally enjoy running iPhone apps at double size on the iPad and it sounds like that's what you're proposing to do.
In your storyboard you can drag and drop from your iPhone screens to iPad to get all of the elements into the iPad storyboard. Then maybe you will tweak a bit to make it more iPad friendly.
As far as I know, you will need to create a new storyboard and set that as the storyboard for iPad (app settings). You will then need to create the content manually (you can copy and paste the objects and use the existing controller classes though (will need to wire up the objects).

Resources