gpt4 book ai didi

ios - 如何在 MPMovieplayerViewController 上添加标题并在点击时隐藏它

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:10:44 24 4
gpt4 key购买 nike

我需要在 MPMoviePlayerViewController 的顶部工具栏上添加一个标题,如果正在播放视频,用户点击应该隐藏标题,就像它隐藏任何其他控件一样。

目前我正在添加一个 UILabel 作为 moviePlayer View 的 subview 。虽然这种方法在顶部栏上添加了一个标题(我相应地设置了框架),但它不会在用户点击屏幕时隐藏标题。

是否有任何直接的 api/hack 可以让我访问 MPMoviePlayerViewController 的顶部工具栏?我在想,如果我可以将标题添加为顶部工具栏的 subview ,隐藏过程将由 MPMoviePlayerViewController 处理。有什么想法吗?

提前致谢!

最佳答案

请注意,我的回答是指 MPMoviePlayerController,而不是 MPMoviePlayerViewController。我建议您直接使用它,或者通过它在 MPMoviePlayerViewController 上的引用来使用它。

首先,切勿将任何内容直接添加到 MPMoviePlayerController 的 View 中。这很容易产生各种奇怪的副作用,并且在文档中明确建议不要这样做。而是使用它的 backgroundView 来托管您的自定义内容或 MPMoviePlayerControllerview 的父级(使其成为同级)。

但话又说回来,如果用户点击或只是等待,那将无法解决您描述的让该 View /标签/任何内容与控件一起消失/重新出现的问题。

有很多方法可以做到这一点,但恐怕这些都处于灰色地带 - 或者换句话说,有可能被 Apple 拒绝。事实上,这不仅仅是一个灰色地带,而且明显违反了 Apple 的开发指南。

只是,我过去曾在主要应用程序上使用过此技巧,但从未被检测到/拒绝过。

首先,您需要找到 MPMoviePlayerController 实例的界面 View 。

/**
* This quirky hack tries to locate the interface view within the supposingly opaque MPMoviePlayerController
* view hierachy.
* @note This has a fat chance of breaking and/or getting rejected by Apple
*
* @return interface view reference or nil if none was found
*/
- (UIView *)interfaceView
{
for (UIView *views in [self.player.view subviews])
{
for (UIView *subViews in [views subviews])
{
for (UIView *controlView in [subViews subviews])
{
if ([controlView isKindOfClass:NSClassFromString(@"MPInlineVideoOverlay")])
{
return controlView;
}
}
}
}
return nil;
}

UIView *interfaceView = [self interfaceView];

现在您已获得实例,只需将您的 View /标签/任何内容添加到该 View 即可。

[interfaceView addSubview:myAwesomeCustomView];

关于ios - 如何在 MPMovieplayerViewController 上添加标题并在点击时隐藏它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15805165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com