将AVPlayerViewController放在UIView内 [英] Place AVPlayerViewController inside UIView

查看:107
本文介绍了将AVPlayerViewController放在UIView内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有一个对话框视图,底部有四个控件.每个控件都在对话框中加载不同的视图.这些控件之一是在对话视图中设置AVPlayer并在播放它.不幸的是,AVPlayer本身没有播放控件.

AVPlayerViewController如何具有播放控件. 是否可以在 UIView 内部放置 AVPlayerViewController ,这样它就不会作为新屏幕启动?将其放置在我的UIView中,以便一切都在我的Dialgoue中进行.

解决方案

您可以初始化AVPlayerViewController并将其作为子级添加到ViewController,并将其作为子视图插入.

[self addChildViewController:yourPlayerViewController];
[self.view addSubview:yourPlayerViewController.view];
[yourPlayerViewController didMoveToParentViewController:self];

并删除它:

[yourPlayerViewController willMoveToParentViewController:nil];
[yourPlayerViewController.view removeFromSuperview];
[yourPlayerViewController removeFromParentViewController];

编辑SWIFT方法: 在此处查看Swift

Currently I am having a dialogue view with four controls at the bottom. Each control is loading a different view inside the dialogue. One of these controls is setting an AVPlayer inside the dialogue view and is playing it. Unfortunately the AVPlayer itself comes without playback controls.

The AVPlayerViewController how ever does have playback controls. Is it possible to place a AVPlayerViewController inside a UIView so that it does not get started as a new screen? I would like to place it inside my UIView so that everything is taking place inside my dialgoue.

解决方案

You can initialize the AVPlayerViewController and add it as a child to your ViewController , and insert it as a subview.

[self addChildViewController:yourPlayerViewController];
[self.view addSubview:yourPlayerViewController.view];
[yourPlayerViewController didMoveToParentViewController:self];

And to remove it:

[yourPlayerViewController willMoveToParentViewController:nil];
[yourPlayerViewController.view removeFromSuperview];
[yourPlayerViewController removeFromParentViewController];

EDIT SWIFT METHOD: Check here for Swift

这篇关于将AVPlayerViewController放在UIView内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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