如何从UITabBarController呈现MPMoviePlayerViewController? [英] How to present MPMoviePlayerViewController from a UITabBarController?
问题描述
我有一个视图控制器已添加到 UITabBarController
。在这个视图控制器中,我有一个按钮,使用 MPMoviePlayerViewController
打开一部电影。
I have a view controller that's been added to a UITabBarController
. In this view controller I have a button that opens up a movie using MPMoviePlayerViewController
.
当我播放电影时,顶部导航栏仍然叠加在电影的顶部,有效地阻挡了部分屏幕。
When I play the movie, the top navigation bar is still overlayed on top of the movie, effectively blocking out a portion of the screen.
但是,当这个视图控制器不在 UITabBarController
中时,电影可以正常播放。
When this view controller isn't inside a UITabBarController
, however, the movie plays fine.
任何人都知道发生了什么事?
Anyone know what's going on?
推荐答案
想出来。我觉得事情变得很糟糕,因为 MPMoviePlayerViewController
有一个方法被添加为 UIViewController
的一个名为 presentMoviePlayerViewControllerAnimated :
。通常你会在你的 UIViewController
中这样称呼它:
Figured it out. I guess things get wonky because MPMoviePlayerViewController
has a method added as a category to UIViewController
called presentMoviePlayerViewControllerAnimated:
. Normally you would call it like this in your UIViewController
:
[self presentMoviePlayerViewControllerAnimated:mp];
但在这种情况下,如果您已将视图控制器添加到 UITabBarController
stack, self
是标签栏控制器中的视图控制器,我想这会让事情变得棘手。修复是使用父视图控制器调用 presentMoviePlayerViewControllerAnimated:
,在我的情况下,是另一个 UIViewController
的UITabBarController
。我只是引用父视图并将其添加到我的视图控制器的 init
方法,然后调用类似 [parentController presentMoviePlayerViewControllerAnimated:mp]
。
But in this case, if you've added your view controller to a UITabBarController
stack, self
is your view controller within the tab bar controller, and I guess this makes things screwy. The fix is to call presentMoviePlayerViewControllerAnimated:
with the parent view controller, which in my case, was another UIViewController
that was housing UITabBarController
. I simply referenced the parent view and added it to my view controller's init
method, then called something like [parentController presentMoviePlayerViewControllerAnimated:mp]
.
哇。希望能帮助别人。
这篇关于如何从UITabBarController呈现MPMoviePlayerViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!