简体   繁体   English

如何从视图控制器在所有视图控制器中添加视图

[英]How to add a view in all view controllers from a view Controller

player View Controller Snap I am developing a Audio Player Application in swift 3 . player View Controller Snap我正在迅速开发一个音频播放器应用程序3。 I have a Player view controller which have some audio Control buttons and this view controller connected with others 'play list' view controller . 我有一个播放器视图控制器,其中有一些音频控制按钮,并且此视图控制器与其他“播放列表”视图控制器连接。 From my home and other view controller I make this player view controller appears as 'present modally' . 从我的家和其他视图控制器中,使此播放器视图控制器显示为“模态呈现”。 Now when I back/ go to another view without making player stop I need to add a common view that has 'Stop Button' and other audio controller and appears in all the view controllers. 现在,当我不停播放器而退回/转到另一个视图时,我需要添加一个具有“停止按钮”和其他音频控制器并出现在所有视图控制器中的通用视图。 (It has Background Audio Compatibility) I'm a new comer in swift.Trying to figure out all the steps to do that. (它具有背景音频兼容性)我是swift的新手。尝试找出实现此目标的所有步骤。 Any help is appreciated. 任何帮助表示赞赏。 Thanks! 谢谢!

This is more about UI design than it is about Swift. 这更多的是关于UI设计,而不是Swift。 One possibility would be to create a container view controller that owns your audio controls and has a container view for the various other view controllers that you have to display. 一种可能性是创建一个容器视图控制器,该控制器拥有您的音频控件,并具有您必须显示的各种其他视图控制器的容器视图。

(See: https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html ) (请参阅: https//developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html

The container controller would manage the visibility of the controls and the amount of space allocated to them and to the content views. 容器控制器将管理控件的可见性以及分配给它们以及内容视图的空间量。

One solution maybe to make the player view controller just a view instead of a view controller. 一种解决方案可能是使播放器视图控制器只是视图而不是视图控制器。 You'd do that by making it a xib. 您可以将其设为xib。 From all your view controllers you could add this player xib as a subView to the view controller. 您可以从所有视图控制器中将此播放器xib作为子视图添加到视图控制器。 This depends on how many view controllers you have. 这取决于您拥有多少个视图控制器。 You'd also need a service that in the background updates the player view. 您还需要在后台更新播放器视图的服务。 This could be done with notifications, where notifications could be sent out from the player controller logic and the view controllers would receive the player updates notifications and in turn update the player view. 这可以通过通知来完成,其中可以从播放器控制器逻辑发出通知,并且视图控制器将接收播放器更新通知,并依次更新播放器视图。 A bit hard to explain in a paragraph. 在一段中很难解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在iOS中将相同的子View控制器添加到父View控制器? - How to add the same child View controllers to a parent view controller in iOS? 为UITabbarController中的所有视图控制器添加公共视图 - Add a common view for all view controllers in UITabbarController 从另一个视图控制器通知视图控制器 - Notify view controllers from another view controller 如何从多个视图控制器推送到一个视图控制器对象 - How to push to one view controller object from multiple view controllers 如何在iOS中以编程方式从基本UIViewController向我的所有视图控制器添加视图 - How to add a view to all of my view controllers from base UIViewController programmatically in iOS 如何从未连接到其他视图控制器的视图控制器传输回视图控制器? - How do I transfer back to a view controller from a view controller that is not connected to other view controllers? 从选项卡控制器完全删除所有视图控制器 - removing all view controllers completly from tabbar controller 如何将条形按钮项添加到导航控制器中的所有视图控制器 - How do you add a bar button item to all View Controllers in a Navigation Controller 如何“弹出”导航控制器及其所有视图控制器 - How to 'pop' a navigation controller and all of its view controllers 更改根视图控制器并关闭所有视图控制器 - Change root view controller and dismiss all view controllers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM