Scaling UIViewController and children to fit iPad or iPhone screens - ios

I am developing a game for the app store and have been using Sprite Kit. In Sprite Kit to have the game work on both the iPhone and the iPad I set the SKScene's scaleMode=SKSceneScaleModeAspectFill and made the screen proportions so it would fit the iPhone 4&5 screens as well as the iPad and this has worked well. Now I am building the menus for the app, but I am not using Sprite Kit for this. Instead I am using Collection Views, Buttons, images, etc. I am not seeing a similar property to scale the view to a certain size depending on what device I am on. Since I am using images for all of my buttons, ideally just proportionately scaling everything would be the simplest way to achieve what I am looking for. Am I missing something as far as how best to proceed with this? Thanks in advance.

You are describing Auto Layout. It is the feature specifically designed for this very purpose, i.e. to change sizes and distances of interface objects in response to the fact that the screen is a different size.
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/Introduction/Introduction.html
However, for a size difference as great as the iPad vs. the iPhone, if you have a universal app, it sometimes makes sense to design two different interfaces. It is easy to set up the Info.plist or your initial code to load the correct interface depending on which device type this turns out to be at runtime. In fact, if you start by making a Universal app, the project will simply come with two storyboards, one for iPhone and one for iPad, which are loaded automatically.
Another option (which didn't occur to me at first because I don't write these kinds of game) is to scale a superview by applying a view transform (i.e. set its transform to a scale transform). That scales the view's coordinate system, so all its subviews will change to match, just like a drawing.

Related

Manually adjusting positions of UI elements in Xcode's storyboard

Instead of having to use xcodes constraints, which I can never get to work right, is there a way to manually set where UI elements are on the screen? I noticed that if I'm on the attributes bar for the view controller, I can set simulated metrics's size to any iphone size I want.
Then I can position the UI elements on the screen where I please. When I build and run, it always mimics exactly what I set up. However, it only works for the particular size of the iphone I specified. Is there a way to do all the sizes manually without making several xcode projects?
Thanks!
There is multiple other solution that is not as good as constraints.
1) Use frame property of views to place them
2) Use size classes to do different placement for iPad iPhone etc
3) Use suggested constraints - you are placing views and than you can give XCode possibility to create constraints for you suggesting what you want from your views placement.
You're going to want to learn how to properly use constraints. The approach you're trying to do would have been okay when there was only one screen size, but now we have three different sizes of iPad, two watch sizes and four different iPhone sizes. Here's a link to a tutorial from Ray Wenderlich (he has some pretty good tutorials to get you started n a wide variety of things). https://www.raywenderlich.com/115440/auto-layout-tutorial-in-ios-9-part-1-getting-started-2
The auto layout in storyboard on Xcode 7 isn't my favorite, but when Xcode 8 comes out it provides device specific sizes for views that makes auto layout much easier. So maybe Xcode 8 will provide a better solution to your problem!

Updating controller from iPhone to iPad with size classes?

I have been using autolayout and constraints to make my app look pretty on every iPhone, and it looks ok so far. I am having problem with iPad. I have a screen that when viewed on iPad has to much blank space.
I would like to use bigger images, and larger font. Maybe add one more label. Can I do this with sizeclasses, or i have to do it some other way?
Yes, you can do all that with size classes – and indeed they are the preferred solution for this, because you automatically get support for slide over and split view.
If you're using Interface Builder (which, quite frankly, is by far the best way to work with size classes), you'll see little + buttons next to many configuration option of your user interface. For example, you mentioned larger font: right there to the left of the font options is a + symbol, and clicking it lets you add a different font size for specific size classes.
I made an app a few months ago that worked on all iPhones and iPads as well as Apple TV, all using the same base storyboard with customisations using size classes. There's such a big gap between the tiny iPhone 4s and the massive iPad Pro that size classes were basically essential. And yes, split view worked flawlessly out of the box, which was a bonus.
My primary advice: Design for your smallest screen first, then add size classes to configure the largest options. You can then choose some views to either not be installed (it's a checkbox) or just be sized down very small to make sure your UI looks and works great in its most challenging environment. If you can do that, making iPad work is a cinch because it feels like you have acres of space ;)
Another useful tip that enough people know about: Enable the assistant editor, then choose Preview mode for your storyboard. This lets you see how your layouts look on multiple different devices and orientations simultaneously, as you work. If you're looking to make best use of size classes (and the massive difference in space between iPhone and iPad) using the previewer is essential.

Playable area in Spritekit iOS

I am making a landscape universal game with Spritekit and Swift in Xcode 6.1. I have been researching about how to make a universal app, and there seems to be a lot to do in regards to layout so that your game looks the same across all devices.
I have read that you can do this by defining a "playable area" in which you put all your game features into. The link below shows a image explaining the playable area idea.
http://cdn5.raywenderlich.com/wp-content/uploads/2013/09/Aspect-Ratio-Diff.jpg
Apart from the 1 tutorial I have found online talking about this, (which wasn't for Swift) I cannot find anything about how to actually "define" a playable area for Swift in Spritekit.
Is there a way I can create a rectangle, lets say on the iPhone 6 for example, so that it will cover all devices as long as I build my game within that rectangle?
Basically how do I define a "playable area" so that I can see the boundaries that I have to build my app within? Like in the linked picture?
To make the layout appear the same on every device , assuming u support iPhone 5 and above only . You can make use of .Aspectfill under your GameViewController to scale the scene to fit all the resolutions. This means that you will be using the iOS 5 simulator and that you will relinquish support of iPhone 4s.
The best way to define a playable area would be to either create a rectangle node that encompasses a certain area while ensuring that your physics world is showing physics for testing.
If you want to build for each screen size natively, you would have to adjust your content manually as technically , devices such as the iPhone 6 plus for example are designed so you can see more things.

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!

iOS storyboard layout

I am working on an app and have come into some graphical problems when designing my app.
First off, my app is only support by iPhone. My current storyboard is using the iPhone 5 as the screen size, so everything screws up when I try to run in iPhone 4 and 4S. Is there a way to make multiple storyboards for each different screen size? Or do you all have another solution?
Thanks!
- Brad
There is a way to make different storyboards for separate screen sizes, but another way to do it is like this:
Whenever you add objects to your views, be sure to have them aligned to something (using constraints). If all items are relative to other items, then most likely the layout will be fine on all devices. Also, if you find that your controls start overlapping, then perhaps you ran out of room. In that case simply add a scroll view to your layout, and then put the controls on top of it. Then, it won't scroll on the larger screens because all controls are shown, but on smaller devices it will allow you to scroll down to see the rest of the objects.
Good luck.
There is a small button in the lower right hand corner that lets you toggle between 3.5" and 4" screen sizes so you can see how it will look on different devices. By using Auto Layout introduced in iOS 6 you can make sure to set up your constraints so that your UI looks good on both older and newer iPhones.

Resources