ios - 如何在目标 c 中隐藏 AVPlayer 屏幕?
问题描述
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(playMethod)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Play" forState:UIControlStateNormal];
[button setTitleColor:[UIColor purpleColor]
forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
}
- (void)playMethod {
controller = [[AVPlayerViewController alloc] init];
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = CGRectMake(15,50,345,300);
controller.player = player;
controller.showsPlaybackControls = YES;
player.closedCaptionDisplayEnabled = NO;
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 addTarget:self
action:@selector(backMethod)
forControlEvents:UIControlEventTouchUpInside];
[button1 setTitle:@"Back" forState:UIControlStateNormal];
button1.frame = CGRectMake(50.0, 0.0, 160.0, 40.0); // set your own position
[controller.view addSubview:button1];
[player pause];
[player play];
}
-(void)backMethod
{
controller.view.hidden=YES;
[player pause];
}
我正在尝试在 AVPlayer 中播放 RTMP URL,它工作正常,但问题是,我在播放器本身上创建了一个后退按钮,但是当我调用它的方法 (backMethod) 时没有任何反应。我想要,当我单击后退按钮时,它应该隐藏该屏幕(播放器屏幕)并且应该出现播放按钮屏幕。
解决方案
尝试将您的播放器视图放在 viewController 视图的子视图中。
并隐藏您的子视图而不是隐藏 PlayerViewController 的视图,因为它是由 PlayerViewController 本身管理的。
推荐阅读
- html - 从两侧围绕图像/形状包装两列文本html css
- c++ - 如何从特定位置开始读取文件c ++
- drools - 如何使用java应用程序在本地执行drools kjar而不使用kie-server容器?
- ios - URLSession 不返回任何内容
- c - 您可以在指向数组的指针中打印内容吗?
- clockify - 检索 Clockify 工作区时出现错误 500
- ajax - 如何克服 REST API 中的超时?
- c++ - 通过 AWS C++ SDK 拒绝访问 SQS (createqueue/deletequeue)
- javascript - 带有身份服务器 4 身份验证的 Outlook 加载项项目,无法与身份服务器连接
- vba - 如何根据 PowerPoint 中的计算使形状可见