Skip to content

Instantly share code, notes, and snippets.

@lessthanyouthink
Created February 23, 2012 21:39
Show Gist options
  • Save lessthanyouthink/bbae6291c4f6bf05d1eb to your computer and use it in GitHub Desktop.
Save lessthanyouthink/bbae6291c4f6bf05d1eb to your computer and use it in GitHub Desktop.
Here's a workaround for a bug introduced by iOS 5.0: when displaying a full-screen video from a UIWebView in a view controller within a UINavigationController, the view controller won't receive the typical willRotate / didRotate calls, and won't be querie
#define kVideoOverlayControllerClass NSClassFromString(@"MPInlineVideoViewController")
@implementation CJVideoRotationNavigationController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([self.topViewController isKindOfClass:kVideoOverlayControllerClass]) {
NSUInteger index = [self.viewControllers indexOfObject:self.topViewController] - 1;
if (index < self.viewControllers.count) {
return [[self.viewControllers objectAtIndex:index] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
}
return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if ([self.topViewController isKindOfClass:kVideoOverlayControllerClass]) {
NSUInteger index = [self.viewControllers indexOfObject:self.topViewController] - 1;
if (index < self.viewControllers.count) {
[[self.viewControllers objectAtIndex:index] willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
if ([self.topViewController isKindOfClass:kVideoOverlayControllerClass]) {
NSUInteger index = [self.viewControllers indexOfObject:self.topViewController] - 1;
if (index < self.viewControllers.count) {
[[self.viewControllers objectAtIndex:index] didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
}
}
@end
@lessthanyouthink
Copy link
Author

NB: You may want to implement a check to see what the OS version is, as this is unnecessary with iOS 4 – though everything still behaves properly with this code as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment