-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.