Disable landscape orientation for iPhone only using size classes - ios

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.

Related

Size Classes & Plus Phone

So all phones have compact width/regular height in portrait. Plus phones have regular width/compact height in landscape while others have compact width/compact height.
So the only in LANDSCAPE orientation you can distinguish a plus model phone.
Question
Is there a way to distinguish a plus model phone in portrait orientation?
without checking for:
Screen resolution
Screen scale
Device strings
NOTE:
Checking for screen resolution/scale, device strings are plausible, however trying to stay away from those. For example, Apple had to put Contact Icons for Favorites for iPhone Plus in Portrait. So there has to be a formal way to do this?
You are getting it wrong. The main purpose to make the adaptive layout is it can adapt to any screen size irrespective of device.
You should not think about these devices screen size while making layouts. You should be thinking of size classes.
If your layout can work in above size classes than it should work in respective phones. Also if you are looking for orientation but your app support the multitasking than your layout might not work with that.
Ideally, Your app should have layout that can work in any screen size because apple is releasing new devices with different screen sizes so your app should be compatible and work in every layout.
But that is ideal world. You can handle most of your layout with size classes. In some cases you need to handle the special scenarios.

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.

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.

Autolayout in iPhone Portrait Mode

I have to design an app for all iPhone size portrait mode only. I am using storyboard and setting constraints using storyboard itself. What makes me confuse is Size Classes. Since my requirement is iPhone portrait only, I am using Size Class compact Width|regular Height. My question is can I disable the Size Classes cause working only for iPhone portrait mode. If yes, then can I design with Size Classes disabled for all iPhone size. What is the right approach?
Intuitively, prior to size classes, storyboard UI was designed by doing a separate interface for each iPhone size. Since the advent of a broad range of device sizes, size classes have been incorporated. Considering that your app may have to run on older devices, there is still a difference in size between iPhones in portrait mode. Because of this, you would likely have to make a separate interface for each orientation, which I have not tried. I believe the correct approach would be to simply design for the size class that you selected.
If you are only making your application for iPhone portrait not necessary to use the size classes. You just have to set proper contract which are in the size indicator.
It's my opinion for it.
If you are developing for iPad and iPhone size class is the best option.
Size classes deal with the problem of multiple orientations(portrait and landscape) and different devices(iPhone and iPad). You cannot differentiate between two different screen sizes for iPhone using a size class. Similarly you cannot differentiate between iPad mini(portrait) and iPad Air(portrait) on behalf of size classes.
All iPhones in portrait has the same size class behavior i.e Compact(width) | Regular(height), be it 3.5", 4.0", 4.7" or 5.5". Similarly all iPhones in landscape has Regular(width) | Compact(height) size class. Size classes aren't the solution to the problem you are facing.
In order to handle multiple screen sizes for iPhone in portrait, the best bet would be to make use of autolayouts. Pin your views with the boundaries so that they will get stretched or contracted on different screens. Similarly bind your labels with the boundaries of their superview so that they will grow too. Also you can make use of aspect-ratio constraint that will allow to grow your view and images relative to the aspect-ratio of the element rather than increasing them horizontally to end up with an elongated look.
If you are new to autolayouts I will highly recommend watching the following sessions from WWDC2012:
Introduction to Auto Layouts
Auto Layouts by Example
Best Practices for Mastering Auto Layouts

Appropriate way to manage different views for portrait and landscape?

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.

Resources