【问题标题】:MPMoviePlayer overlay in fullscreen mode (iPad)全屏模式下的 MPMoviePlayer 叠加层 (iPad)
【发布时间】:2010-10-28 18:20:37
【问题描述】:

我想在我的视频播放器全屏播放时添加一个按钮。我在我的视频播放器上创建了一个叠加层,它在 iPhone 上运行良好。我尝试在 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 mpmovieplayercontroller iphone


    【解决方案1】:

    几周前我找到了解决这个问题的方法:

    似乎这种方法在 iPad 上不起作用(我没有检查过 iPhone SDK 4>),所以为了绕过它,您可以执行以下操作。

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

    我发现的唯一问题是它们不遵守视图的方向规则,我不得不在视图的 willRotateToInterfaceOrientation 方法中手动编写旋转代码。

    【讨论】:

    • 你能解释一下你是如何处理方向的吗?很高兴看到一些代码。谢谢
    • 我以同样的方式添加了叠加层。你解决旋转问题了吗?
    【解决方案2】:

    @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'
        }
    

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 2018-07-22
      • 1970-01-01
      • 2013-10-13
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多