我在我的UIWebView中使用嵌入式youtube,我的viewcontroller处于纵向模式,但我无法在全屏风景中看到视频。我尝试了Stackoverflow的许多解决方案,但没有一个在iOS 7上运行。
答案 0 :(得分:1)
当我遇到类似的问题时,我所做的是:
这是我使用的代码(虽然它适用于iOS6,所以它可能不同
-(void) receivedRotate: (NSNotification*) notification
{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
//Using this part to find the view controller on top (the one that's showing the video in fullscreen).
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
//After a little testing, the class of that controller is MPInlineVideoFullscreenViewController
if ([topController isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")]) {
topController.view.transform = CGAffineTransformMakeRotation(M_PI_2);
//The 20 and -20 are to prevent the movie from going over the status bar
topController.view.frame = CGRectMake(0, 20, self.view.frame.size.width,self.tabBarController.view.frame.size.height - 20);
}
}
答案 1 :(得分:0)
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
-(void) receivedRotate: (NSNotification*) notification
{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
//Using this part to find the view controller on top (the one that's showing the video in fullscreen).
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
if ([topController isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {
switch ([UIDevice currentDevice].orientation) {
case UIDeviceOrientationFaceUp:
NSLog(@"UIDeviceOrientationFaceUp");
break;
case UIDeviceOrientationFaceDown:
NSLog(@"UIDeviceOrientationFaceDown");
break;
case UIDeviceOrientationLandscapeLeft:
NSLog(@"UIDeviceOrientationLandscapeLeft");
topController.view.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
case UIDeviceOrientationLandscapeRight:
NSLog(@"UIDeviceOrientationLandscapeRight");
topController.view.transform = CGAffineTransformMakeRotation(-M_PI_2);
break;
default:
break;
}
topController.view.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height);
}
}