在MPMoviePlayerController顶部添加视图 [英] Adding a view on top of a MPMoviePlayerController

查看:71
本文介绍了在MPMoviePlayerController顶部添加视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个全屏播放的MPMoviePlayerController.然后,我想在影片上方添加一个UIButton,但是它没有显示.

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

当我记录子视图列表时,总是使按钮位于MPMovieView和MPSwipable视图之后的最后一个位置,但是没有显示.

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.

我可以通过禁用[mpc setFullscreen:YES]并将电影视图的框架设置为父视图的边界并设置纵横比缩放模式来解决此问题.我猜这不是最干净的解决方案,但对我有用.

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

推荐答案

在编写时将按钮添加到MPMoviePlayerController上:

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

无论如何,请不要使用[mpc play];,而最好使用[mpc prepareToPlay];(性能问题)

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

这篇关于在MPMoviePlayerController顶部添加视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆