Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Callback when interface rotation ENDED in iOS 9?

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.

like image 282
Luke Avatar asked Mar 06 '26 21:03

Luke


1 Answers

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.

like image 124
Konstantine Dementiev Avatar answered Mar 10 '26 12:03

Konstantine Dementiev