Adding a view on top of a MPMoviePlayerController

点点圈 提交于 2019-12-02 03:38:07

问题


I have a MPMoviePlayerController that plays fullscreen. Then I want to add a UIButton above the movie, but it doesn't show up.

I have already tried inserting the view above the movie view like this:

mpc =[[MPMoviePlayerController alloc]initWithContentURL:url];
[mpc setMovieSourceType:MPMovieSourceTypeFile];   

[self.view addSubview:mpc.view];
**[self.view insertSubview:self.backButton aboveSubview:mpc.view];**

[mpc setFullscreen:YES];

mpc.controlStyle = MPMovieControlStyleNone;

[mpc play];

And I have also tried adding the subview to the movie controller view, like I read in a similar question:

**[mpc.view addSubview:self.backButton];**
[self.view addSubview:mpc.view];

When I log the list of subviews I always get the button in the last position, after the MPMovieView and the MPSwipable view, but it doesn't show up.

EDIT:

I've been able to work it around by disabling [mpc setFullscreen:YES] and setting the frame of the movie's view to the bounds of the parent view and setting an aspect-fill scaling mode. Not the cleanest solution I guess, but it works for me.

mpc.view.frame = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, self.view.bounds.size.height);

UIButton *myButton = [[UIButton alloc]initWithFrame:CGRectMake(100, 500, 100, 100)];

myButton.backgroundColor = [UIColor blueColor];

mpc.controlStyle = MPMovieControlStyleNone;
mpc.scalingMode = MPMovieScalingModeAspectFit;

[self.view addSubview:mpc.view];

[self.view addSubview:myButton];

[mpc prepareToPlay];

回答1:


Add your button over the MPMoviePlayerController as you wrote:

[mpc.view addSubview:self.backButton]

Maybe your button is hidden or nil. Try to set your player:

mpc.controlStyle = MPMovieControlStyleFullscreen;

Anyway, I do it like this:

 MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] init];
 mp.controlStyle = MPMovieControlStyleFullscreen;
 UIButton *btnInfo = [[UIButton alloc] initWithFrame:your_frame];
 [mp.view addSubview:btnInfo];

Anyway, don't use [mpc play]; you better use [mpc prepareToPlay]; (Performance issues)



来源:https://stackoverflow.com/questions/21000905/adding-a-view-on-top-of-a-mpmovieplayercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!