MPMoviePlayer覆盖全屏模式(iPad)

问题描述:

我想在全屏播放时在我的视频播放器上添加一个按钮。我在我的电视机上创建了一个叠加层,它在iPhone上运行得非常好。我尝试在iPad上做同样的事情,但按钮从不出现。MPMoviePlayer覆盖全屏模式(iPad)

这里是我的代码:

NSArray *windows = [[UIApplication sharedApplication] windows]; 
if ([windows count] > 1){ 
     UIWindow * moviePlayerWindow = [windows objectAtIndex:1]; 
     NSArray * subviews = [moviePlayerWindow subviews]; 
     UIView * videoView = [subviews objectAtIndex:0]; 
     [videoView addSubview:myButton]; 
} 

它接缝像iPad这么想的创建全屏模式的UIWindow。

任何人对我如何做到这一点有任何想法?

谢谢!

我找到了解决这一问题的几个星期前:

看来这种方法并不在iPad上正常工作(我还没有检查iPhone SDK 4>),所以为了避开它,你可以做以下。

将视频和设置添加到全屏后,您可以直接将控件添加到UIWindow(例如[[[[[[UIApplication sharedApplication]窗口] objectAtIndex:0] addSubView:myView]),它们将出现在您的顶部视频视频。

我发现的唯一问题是,他们不服从视图的方向规则,我手动必须在视图的willRotateToInterfaceOrientation方法中编写旋转代码。

+1

你能解释你如何处理方向?很高兴看到一些代码。谢谢 – Alex1987 2011-04-05 08:04:30

+0

我以同样的方式添加了覆盖。你解决了轮换问题吗? – 1110 2011-04-29 06:25:21

@tigermain的解决方案起作用。

[[[[UIApplication sharedApplication] windows] objectAtIndex:0] addSubView:myView]

但是添加到窗口的意见不遵循的方向。

解决方案是使用NSNotificationCenter,UIApplicationDidChangeStatusBarOrientationNotification。

// assign a notification 
    id center = [NSNotificationCenter defaultCenter]; 
    [center addObserver:self 
      selector:@selector(didRotate:) 
       name:UIApplicationDidChangeStatusBarOrientationNotification 
       object:nil]; 

    // this method will get called when the orientation changes 
    -(void) didRotate:(NSNotification*)notification { 

     UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
     NSLog(@"%d", orientation); 
     // ... transform view accordingly to the enum 'UIInterfaceOrientationXXX' 
    }