I haven’t seen a definitive answer to this question yet, lots of noise around the iOS 8 changes, but I’d like to address it for iOS 9:
What is the correct way to get a callback after an interface orientation change ENDS?
As of iOS 9, didRotateFromInterfaceOrientation: has been deprecated, and the official documentation tells us to use viewWillTransitionToSize:withTransitionCoordinator instead. This gives us (through the transitionCoordinator) a means of animating alongside the transition, and a completion block, but no direct callback for the bona fide ‘end’ of the transition.
The other method from the transitionCoordinator is notifyWhenInteractionEndsUsingBlock:, but this appears to report the end of the interactive part of the transition, not the entire thing.
So, is the “official” way to do this to implement animateAlongsideTransition:completion, and simply ignore the animation option?
I realise we can still use good old didRotateFromInterfaceOrientation:, but it’s always better to modernise where possible.
Yes, you can ignore animation option, just use 'nil' for it.
Example from WWDC 2014 'View Controller Advancements in iOS 8':
- (void) viewWillTransitionToSize:(CGSize)s withTransitionCoordinator:(UIVCTC)t
{
orientation = [self orientationFromTransform: [t targetTransform]];
oldOrientation = [[UIApplication sharedApplication] statusBarOrientation];
[self myWillRotateToInterfaceOrientation:orientation duration:duration];
[t animateAlongsideTransition:^(id <UIVCTCContext>) {
[self myWillAnimateRotationToInterfaceOrientation:orientation duration:duration];
}
completion: ^(id <UIVCTCContext>) {
[self myDidAnimateFromInterfaceOrientation:oldOrientation];
}];
}
Works fine with iOS 9.
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