Last active
July 27, 2018 04:27
-
-
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
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
/* | |
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! works like a charm!