Detecting iOS 8 orientation change in UIView
I am discovering regular and compact sized classes using TraitCollectionDidChange in iOS8.
I'm trying to fit a certain dataset horizontally to fit the screen and it doesn't fit the Horizontal Class Regular on a Portrait iPad Mini, but there will be a lot of room in the landscape.
The problem is that the Horizontal SizeClass is regular in portrait and landscape, so TraitCollectionDidChange does not fire and I am not informed about the Orientation change.
I heard a link to viewWillTransitionToSize
, but this is not available in UIView.
Are Apple saying they don't want the UI layout to differ from the regular horizontal class - the portrait and horizontal Regular - Landscape classes?
If that's okay, how do I tell, in UIView , to change the orientation?
source to share
Just add the - (void) layoutSubviews method to your UIView subclass. It will be called anytime the view is resized. 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 are looking for.
-(void) layoutSubviews
{
[super layoutSubviews];
// your code here...
}
source to share