There are multiple ways of responding to changes to the Split Screen view configuration. Depending on how you want to respond, you may have to use different approaches.
First of all, preferably use Autolayout and Storyboard constraints that allow your views to naturally resize appropriately to most, or all, view size changes.
In some situations, you may need to make layout changes when the Split Screen changes significantly and moves your available screen space from full screen, or almost full screen, to what iOS calls a Compact presentation. If the view handle is dragged enough to cross this boundary, you can get a callback via this view controller method:
Obj-C
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
NSLog(@"split screen area now compact!");
} else if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular) {
NSLog(@"split screen area now regular!");
}
}
Swift:
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
if self.traitCollection.horizontalSizeClass == .compact {
print("split screen area now compact!")
}
}
These methods are called when changing from Compact to Regular size, or vice versa. Not for every adjustment to the Split Screen view handle. In other situations, different code is needed.
As is the case with handling rotations programmatically, you may want to implement this method, which will provide you the final view size:
viewWillTransitionToSize:withTransitionCoordinator:
This method will get called even if the change is not large enough to cross the Regular-Compact boundary. Inspect the size
parameter passed into your method, and see the example, which shows where you can place code that is called before, during, and after the transition.
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
// Code here will execute before the rotation begins.
// Equivalent to placing it in the deprecated method -[willRotateToInterfaceOrientation:duration:]
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
// Place code here to perform animations during the rotation.
// You can pass nil or leave this block empty if not necessary.
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
// Code here will execute after the rotation has finished.
// Equivalent to placing it in the deprecated method -[didRotateFromInterfaceOrientation:]
}];
}
More Reading
I think it's also useful to make use of trait variations and size classes in your storyboards, although that's not a specific answer to this question.