Skip to content

Instantly share code, notes, and snippets.

@jcayzac
Created October 17, 2014 08:14
Show Gist options
  • Save jcayzac/a38d835c345c76b0f506 to your computer and use it in GitHub Desktop.
Save jcayzac/a38d835c345c76b0f506 to your computer and use it in GitHub Desktop.
// Only called on iOS<8
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation __unused)toInterfaceOrientation duration:(NSTimeInterval __unused)duration {
[self _beforeOrientationChange];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation __unused)fromInterfaceOrientation {
[self _afterOrientationChange];
}
// Only called on iOS>8
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[self _beforeOrientationChange];
UIInterfaceOrientation oldOrientation = UIApplication.sharedApplication.statusBarOrientation;
typeof(self) __weak weakSelf = self;
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> __unused context) {
if (oldOrientation != UIApplication.sharedApplication.statusBarOrientation) {
typeof(weakSelf) __strong strongSelf = weakSelf;
[strongSelf _afterOrientationChange];
}
}];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
- (void)_beforeOrientationChange {
// your code here
}
- (void)_afterOrientationChange {
// your code here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment