I created my project back before iOS8 and Xcode 6 came out. I'm supporting down to iOS 6.0, and have two Storyboards, one for iPhone and one for iPad.
Now, in Xcode 6, I'd like to add support for the new screen sizes (iPhone 6/6plus). When creating a new Storyboard, it is using the new format (square), which is good, but I'm not sure how to proceed. Can I decide which devices uses which storyboards? Or is the new Storyboard-setup supported on older iOS-versions?
Can I throw away my old Main_iPhone.storyboard and create a new Xcode6-storyboard (with support for iPhone 6-sizes) while still supporting iOS 6/7? Or do I have to keep the old storyboards to work with versions below iOS8?
If I need to keep them, where do I set the logic for which devices use which storyboards?
we can use more then one story board in one project.and call particular story board and identify the particular viewcontroller according to the identifier.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
PlaceDetailViewController *place=[mainStoryboard instantiateViewControllerWithIdentifier:#"placedetail"];
[self.navigationController pushViewController:place animated:YES];
}
Related
Long time lurker, always tried very hard to search and have found many answers this way. This is the first time I have found nothing that fixes my problem. This is also my first solo app, as I am a new developer.
I have two devices- an iOS 8.1 iPhone 6, and an iOS 7 iPad Mini Retina 2.
I am building my first iOS app. It uses storyboards for a UITabBarController with three tabs, each of which contains a UINavigationController and a custom sub view controller (such as a subclass of tabbarcontroller or collectionviewcontroller).
Under Deployment Info:
Deployment Target is set to 7.0 and Universal. iPhone and iPad both use the MainStoryboard main interface, with all four Device Orientations checked for both.
My AppDelegate starts with:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
UITabBarController *initViewController = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:#"rootTabBarController"];
NSLog(#"%d %d",initViewController.shouldAutorotate,initViewController.shouldAutomaticallyForwardRotationMethods);
[self.window setRootViewController:initViewController];
Note the NSLog; it prints "1 0".
So from what I can see- the tab bar should auto rotate.
On my iPhone, when I turn the device sideways, the status bar on the top rotates- but the content remains upright. If I hit the Home button and switch back to the app while holding it sideways, everything goes wonky- the content rotates but doesn't rearrange the layout, so it remains vertical, and thus gets cut off and there's a big black section on the side.
On my iPad, though- everything works fine! The application rotates as expected and resizes itself.
What am I doing wrong here? Thank you tremendously for any help.
Why are you programmatically loading the storyboard? If there's no specific need to do that, I'd suggest just using the template app delegate code. Better yet, create a completely new, fresh project and just copy over your storyboard. It won't necessarily make sense, but... I bet it will work!
My OS version is OS X Version 10.9.4.
XCode Version is 6.0.1
Everytime I create a new project ,the storyboard is always for ipad even I choose Device to iphone.The old projects with iphone storyboard work fine.But Everytime I create a new project whatever I choose ,it is always ipad storyboad.Please help me!
You can change it programmatically
NSString *storyName = #"MainStoryboard_iPhone";
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPad) {
storyName = #"MainStoryboard_iPad";
}
UIStoryboard *story = [UIStoryboard storyboardWithName:storyName bundle:[NSBundle mainBundle]];
or made by default the storyboard on your settings projects. On General, deployment target, main interface, switch between iPhone / iPad
On xCode 7: select the View Controller, click on Attributes Inspector at the top of the Utilities sidebar (left side.) At the top is a size drop down. Use it to select the size you want to view.
Appears this has to be done for each ViewController.
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.
I've Created an iPhone App.I Want To Make it Universal on Next Version But When I Choose Universal From Deployment Info Menu it Does not Creat Main-iPad Storybiard.Anyway I Created it Myself and When I Tried too Test it on iPAd it shows iPhone storboard!
You have to create an ipad storyboard, click on the ipad button under the universal setting, and then set the ipad storyboard there: Here is what you're needing to do.
Edit:
Since you are still experiencing the iphone look on the ipad, go to your .plist file, and check for:
hope it helps
The storyboards are created and configured automatically when you create the project in universal mode. If you started for iPhone only, and switch to universal later, you'll need to set the different storyboards in the project settings.
To do so, go to project settings and choose your target. Note that in 'Deployment info' under your choice for 'Universal' there are two buttons 'iPhone' and 'iPad'. You can select 'iPad' there and select your iPad storyboard.
You need to create iPad Storyboard, not iPhone.
And You need to select that storyboard at general tab(At targets).
Maybe change in the app delegate this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
To something like this.
UIStoryboard *storyboard;
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPad) {
storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
} else {
storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
}
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