Skip to content

Instantly share code, notes, and snippets.

@akisute
Last active July 27, 2018 04:27
Show Gist options
  • Save akisute/a46c5ec54d27f73b62da to your computer and use it in GitHub Desktop.
Save akisute/a46c5ec54d27f73b62da to your computer and use it in GitHub Desktop.
Dismissing fullscreen movie player from <video> tag in UIWebView with animation and completion handler
/*
WARNING: PRIVATE API CALLS
WARNING: FORCEFUL MEMORY MANAGEMENT
highly recommend to avoid using this code
*/
- (void)exitFullScreenVideo:(BOOL)animated completion:(void (^)(void))completion
{
/*
iOS 6~7の場合
本ViewControllerの上にMPInlineVideoFullscreenViewControllerがfullscreen modalで表示されるような挙動になるので
それを通常通り閉じてやればよい
iOS 8の場合
新しいUIWindowが生成され、生成されたUIWindowのrootViewController.presentedViewControllerがAVFullScreenViewControllerになる
まずAVFullScreenViewControllerを閉じて、それからUIWindowのrootViewControllerをnilにセットしてhiddenにすることでUIWindowを消す
*/
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0) {
BOOL isFullScreenVideoContent = NO;
for (UIWindow *window in [UIApplication sharedApplication].windows) {
if ([window.rootViewController.presentedViewController isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {
[window.rootViewController dismissViewControllerAnimated:animated completion:^{
window.rootViewController = nil;
window.hidden = YES;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[window performSelector:NSSelectorFromString(@"release")];
#pragma clang diagnostic pop
completion();
}];
isFullScreenVideoContent = YES;
break;
}
}
if (!isFullScreenVideoContent) {
completion();
}
} else {
if ([self.visibleViewController isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")]) {
[self dismissViewControllerAnimated:animated completion:completion];
} else {
completion();
}
}
}
@itaen
Copy link

itaen commented Dec 18, 2017

Thanks! works like a charm!

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