Can Size Classes / Trait Collection in iOS be used programmatically when not using Autolayout
Asked Answered
C

1

8

I am not using Auto Layout however I wish to be able to make my (very complex) app adapt to Split View multi-tasking on the iPad. For this, ideally to do it right, I want to support size classes without going down the Auto Layout route. Watching the WWDC 406 session it seems that one can programmatically do this, but I am not sure since they've used Autolayout in every example and even Interface builder does not support it otherwise.

Will I run into any issues if I was to listen to notifications regarding trait changes and do everything programmatically or using pins and struts? I have everything defined in Storyboards but I'd like to be able to support differently sized view controllers when the iPad is showing two apps side by side in iOS 9. Please advise.

Collaborate answered 7/7, 2015 at 1:43 Comment(10)
yes, you can use size classes without autolayout. You can easily test it by creating app from Master-Detail Application template and disabling autolyaout for storyboard.Workingman
Sorry but that's wrong! Did you try this out yourself before commenting? The moment you turn Auto Layout off, it also disables and turns Size Classes off. Without AutoLayout, size classes don't make sense in themselves as the technology depends on auto-layout to do its thing.Collaborate
yes I tried, they still working for me. I saw alert from Xcode and Size Classes checkbox is unchecked. but split view controller's behaviour does not changed and traitCollectionDidChange is called after rotationWorkingman
That then does not suggest that it's using size classes. When you use the word size classes, you're actually referring to Interface Builder's ability to design different classes visually. 'traitCollectionDidChange' will work either way as that is if you were to programmatically do it yourself - which is what my original question was :)Collaborate
oh, you mean change size classes in IB while autolyout is disabled... in this case yes you can't do this. But seems like underhood they still workingWorkingman
No. On the bright side, since you are already using Storyboard, you are most of the way there: while autolayout for a given UIView is an all-or-nothing proposal, each UIView may elect to use or not to use NSLayoutConstraint, independently of that view's siblings.Commercial
I guess you really want to hear yes, but, even with a bounty, it appears that the documentation, sadly, is correct. Any progress?Commercial
Well yes I want to yes :D but not at the expense of getting a link from the Documentation or being forced to use Auto Layout. What I need to know is that if I go down the programmable route of handling traitCollectionDidChange, is that the recommended alternative? Anything else I need to know? I really dislike autolayout as it's complicated for more sophisticated custom UI layouts.Collaborate
Let me answer that I used to abhor AutoLayout and Storyboard until I found this amazing tutorial: raywenderlich.com/50317/…. I now recommend most project I oversee or architect to make the switch. You can do it 1 view at a time (just like load from NIB), so it is not nearly as painful as it sounds. You will be glad you switched, if nothing else, for the portability to iPhone, iPad and Apple Watch. 0 coding is the way to go!Commercial
Sure, but if your iPad and iPhone apps have almost zero commonality in terms of layout and design, and the complexity of the animations you use in between landscape and portrait - it's actually unimaginably painful to use AutoLayout. The last I tried AutoLayout was 1.5 years ago when the performance was so, so bad (especially UITableView), I gave up.Collaborate
C
3

From Apple Documentation:

Enabling Size Classes in Interface Builder

Size classes require Auto Layout. If the checkbox Use Auto Layout isn’t selected when you select Use Size Classes, Xcode prompts you to enable Auto Layout.

Commercial answered 29/7, 2015 at 1:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.