Appropriate way to manage different views for portrait and landscape? - ios

I'm developing an app targeting iOS 7 and above. I'm using storyboard and autolayout, and I have to show different layouts of each storyboard scene depending on the device orientation, I mean, for example: in portrait I may have a button at a certain place that has to be shown in another place in landscape, or I may have controls in portrait that should disappear in landscape and have to rearrange the rest of controls.
My question is: when there are a lot of differences between portrait and landscape, should it be better to manage all this changes by programmatically updating constraints, or should it be better to create different nib files and load the corresponding according to the orientation?

use size classes their will be no problem in giving support to ios7 . I have tested their were no major problems in ios7 while using size classes.

Related

Existing app needs UIScrollView when using Size Classes

I have an iPad app that is written for Portrait mode; I am trying to add Landscape mode to it using Auto Layout. Everything appears to work just by changing the Size Classes in XCode, except some of the pages are longer when displayed in Landscape mode. My thoughts are to just add a UIScrollView to each page that needs it, at the top of the view hierarchy.
Is this the preferred method of solving this issue?
Yes, when designing an app for both landscape and portrait orientations you usually will need to make the content scrollable in landscape orientation.
You can also create a different layout for the landscape orientation and completely re-layout the UI components when the app rotates, but for simplicity putting all of your objects in a scroll view will solve your issue of limited real estate on the screen.

Disable landscape orientation for iPhone only using size classes

I am using adaptive layout with size classes (iOS10).
For an iPad I want to support portrait & landscape views, but for iPhone I only want to support portrait. I don't want to rotate screen for compact height.
iPad is all fine and I have set-up the iPhone views using size classes, so I am thinking I need to somehow detect what size class will be transitioned to and disable rotation if it would go to compact height.
I can see a method called traitCollectionDidChange, but not sure if this is the correct time in the lifecycle to detect this.
There are a few related questions, but I don't see anything that covers this specific scenario.

Swift layout for different orientations

How can I make different layouts for different orientations on ios?
I try to make an layout in landscape to show 6 picture's in 2 rows.
But in portrait I only will show 4 pictures in 2 rows.
I already have 2 different storyboard for iPad and iPhone.
Can I do this over constrains?
Can I do this with different storyboards like in android?pain
iOS has something called Size Classes. You can use a size class to target a specific device and/or orientation. You can choose the appropriate size class at the bottom of interface builder (wAny hAny) and layout your view accordingly.
https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/AboutAdaptiveSizeDesign.html
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/LayoutandAppearance.html
Adding on to #Nitesh's answer: Correct me if I am wrong, I am not very well versed in iOS development as well. I read that it is almost always recommended to use Size Classes while only using one storyboard for all targeted devices. It makes handling issues like screen sizes and orientation much more managable.
In your case, may I suggest using UICollectionView to achieve that effect? It rearranges your tiles based on how much width you have and it supports orientation quite well.

UIViewController Size doesn´t work

Hi im currently developing an Universal app for iPhone, iPod and iPad. I have all view controllers in both storyboards set to Inferred. It works fine on iPhone Retina and on all iPads but when you put it in landscape mode it gets all messed upp and on the iphone 3,5 inch simulator the bottom gets cut off. How can i fix this? Do i have do create seperate view controllers for landscape mode and iphone 3,5? And the write some code that recognizes if its in landscape mode and iphone 4? I thought this worked automatically. Or have i done something wrong?
There is no quick fix/answer to your question.
Since the screen size is different while using horizontal and vertical orientations - it is simply not the same canvas and thus you will need to do some manual work to set it right.
Strategy 1.
Assuming your layout is simple - there are not too many elements and all elements can theoretically fit both horizontal and vertical screen size:
You should use auto layout from the Interface builder - Look at an excellent video from WWDC
https://developer.apple.com/wwdc/videos/
(video 406 - Taking Control of Auto Layout in Xcode 5)
In few words - you set spacers to your elements, aligning them to the end of your view (dynamically), therefore you can make your element shrink and move automatically respecting the current screen orientation.
Strategy 2.
Assuming your UI is complex and will not fit both orientations:
have a different xib file for horizontal and vertical views, this can take some time, but it is a solid solution that always looks good.
You simply need to track changes in orientation and load the appropriate xib.
Your problem will only be solved if you use Autolayouting and for that you need to go through some tutorials
Ray's Tutorial
Another Very well explained tutorial
Going through the above articles will definately help you in solving your problem

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!

Resources