I am detecting Regular and Compact size classes with TraitCollectionDidChange in iOS8.
I am trying to fit a particular set of data horizontally across the screen and it does not fit in Horizontal Class Regular on a Portrait iPad Mini however there would be plenty of space in Landscape.
The problem is that Horizontal SizeClass is Regular in Portrait and Landscape so the TraitCollectionDidChange does not fire and I don't get told about the Orientation change.
I have heard reference to viewWillTransitionToSize
but that is not available in a UIView.
Are Apple saying they do not want UI layout diffs from Horizontal Class Regular - Portrait and Horizontal Class Regular - Landscape?
If it's OK to do it how do I get told, in a UIView, about the Orientation change?
This inherited UIViewController method which can be overridden will be trigger every time the interface orientation will be change.
Another most common solution to dealing with orientation changes by setting the android:configChanges flag on your Activity in AndroidManifest. xml. Using this attribute your Activities won't be recreated and all your views and data will still be there after orientation change.
You can configure which device orientation does your iOS app support in the Xcode target —> General —> Deployment Info section also. Just check the checkbox in the Deployment Info —> Device Orientation section. Below is the explanation of each orientation meaning, you can check multiple checkboxes.
Just add the method -(void) layoutSubviews into your UIView subclass. It will get called any time the view's dimensions change. Don't forget to call [super layoutSubviews] inside your new method.
Then you can check self.traitCollection.verticalSizeClass and self.traitCollection.horizontalSizeClass to see what you're looking at.
-(void) layoutSubviews
{
[super layoutSubviews];
// your code here...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With