全屏模式下的 MPMoviePlayer 叠加层 (iPad)

发布于 2024-09-29 09:54:24 字数 518 浏览 0 评论 0原文

我想在全屏播放时在视频播放器上添加一个按钮。我在我的视频播放器上创建了一个叠加层,它在 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。

有人知道我该怎么做吗?

谢谢!

I want to add a button on my video player when it is playing in fullscreen. I created an Overlay on my videoplayer and it's working very well on an iPhone. I tryed to same thing on a iPad, but the button never appear.

Here's my code :

 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];
}

It seams like the ipad dosen't create a UIWindow for the fullscreen mode.

Anyone have any idea on how I could do this?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心的憧憬 2024-10-06 09:54:24

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

看来这个方法在 iPad 上不起作用(我还没有检查过 iPhone SDK 4>),所以为了解决这个问题,你可以执行以下操作。

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

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

I found a solution to this problem a few weeks ago:

It seems this method does not work on the iPad (I havent checked iPhone SDK 4>) so in order to get round it you can do the following.

After adding your video and setting to fullscreen you can add your controls directly to the UIWindow (e.g. [[[[UIApplication sharedApplication] windows] objectAtIndex:0] addSubView:myView]), they will then appear on top of your video video.

The only problem I have found with this is that they dont obey the orientation rules of the view and I have manually had to program the rotation code in the willRotateToInterfaceOrientation method of the view.

月隐月明月朦胧 2024-10-06 09:54:24

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

The solution from @tigermain works.

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

But the views added to the window do not follow the orientation.

Solution for the orientation is to use 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'
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文