我正在开发的应用程序是纵向的,但是当视频正在运行时(它嵌入在 WebView 中),我需要将视频重新定向为横向模式。我该怎么做?我找到了一个解决方案,它在几天前工作得很好 :)。我相信这是因为 iOS 7 更新,但我不确定。所以,这就是我以前使用的,但它不再起作用了,因为窗口和类名始终为 nil。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
id presentedViewController = [window.rootViewController presentedViewController];
NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;
if (window && [className isEqualToString:@"MPInlineVideoFullscreenViewController"]) {
return UIInterfaceOrientationMaskAll;
} else {
return UIInterfaceOrientationMaskPortrait;
}
最佳答案
我终于自己找到了解决办法!我在 AppDelegate 中实现了以下方法并且有效。我的问题是,一开始我没有检查正确的 View Controller 。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
NSString *className = NSStringFromClass([window class]);
if ([((UINavigationController *)window.rootViewController) respondsToSelector:@selector(visibleViewController)]) {
className = NSStringFromClass([((UINavigationController *)window.rootViewController).visibleViewController class]);
}
if ([className isEqualToString:@"MPFullscreenWindow"] || [className isEqualToString:@"MPInlineVideoFullscreenViewController"]) {
return UIInterfaceOrientationMaskAll;
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
return UIInterfaceOrientationMaskLandscape;
} else {
return UIInterfaceOrientationMaskPortrait;
}
关于objective-c - 如何旋转 UIWebView 中嵌入的视频(仅适用于 iOS 7)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22095982/