2013-02-10 79 views
1

我已经试过这个,但它不工作,我最近7个小时都在努力,请帮助我。我想将自定义按钮添加到MPMoviePlayer的全屏视图中。MPMoviePlayerController在全屏添加子视图

代码:

moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 

     [self.view addSubview:moviePlayerController.view]; 
     moviePlayerController.fullscreen = YES; 

     UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]]; 

     CustomControlsViewController *overlay = (CustomControlsViewController*)[mainStoryBoard instantiateViewControllerWithIdentifier:@"Custom Controls"]; 

     [moviePlayerController.view addSubview:overlay.view]; 

     [moviePlayerController play]; 

回答

10

所有的第一次,从来没有添加任何子视图MPMoviePlayerController的观点本身。将它们添加到其背景视图或其父级作为兄弟。

此所述MPMoviePlayerController文档中进行了讨论:

考虑一个电影播放视图是一个不透明结构。您可以将 您自己的自定义子视图添加到电影顶部的图层内容,但是您的 绝不能修改其任何现有子视图。除了在电影上分层内容 之外,您还可以通过向backgroundView属性中的视图添加子视图来提供自定义背景 内容。

第二,使用适当的全屏的情况下,MPMoviePlayerController不会重用其正常视图,但直接加到它的内容到UIWindow实例。因此,在使用“正确的”全屏模式时,您只有以下选项;找到当前的按键窗口,并在切换到全屏模式后直接添加控件。

像这样的东西应该做的:

//are we in fullscreen-mode? 
if (player.fullscreen) 
{ 
    UIWindow *window = [UIApplication sharedApplication].keyWindow; 
    if (!window) 
    { 
     window = [[UIApplication sharedApplication].windows objectAtIndex:0]; 
    } 
    //we now got a proper window for use of our controls ... 
    //add them to the window instance! 
} 

作为替代,根本就没有使用“适当的”全屏,但调整MPMovieViewController的观点,以覆盖整个屏幕 - 我称之为“假”全屏。此选项的一大优势是您可以使用/捕获/覆盖正常重新定向。

+0

我将在“假”全屏上制作自定义控件,thx! – 1337code 2013-02-11 12:17:19

+0

关于你的第一点 - 我阅读它的方式,可以向movieplayer视图添加子视图,但不要修改任何本机提供的视图(例如遍历子视图并更改它们)。 – Grav 2014-01-29 09:09:27

+0

根据文档“您可以在此属性中的视图中添加子视图,您可以安全地将子视图添加到播放器的视图中。如果要显示自定义回放控件或添加其他与你的应用程序“。 https://developer.apple.com/LIBRARY/IOS/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/index.html#//apple_ref/occ/instp/MPMoviePlayerController/view – SomeGuy 2014-11-17 09:32:52