我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

时间:2022-06-21 18:57:13

I am making a media player app. I have UITableViewControllers that are embedded in Navigation Controller. I would like to somehow make a view that would overlay potentially multiple (2?) of these tableviewcontrollers (one that shows the user's playlists, and the next would show the tracks in the playlist), but only at the bottom, like a now playing bar in (e.g.) Spotify's iOS app (as in the left bottom side of this

我在做一个媒体播放器应用,我有uitableviewcontroller嵌入在导航控制器里。我想以某种方式让一个视图,将覆盖可能有多个(2)表(一个显示用户的播放列表,接下来将显示歌曲在播放列表),但只有在底部,像一个正在酒吧里(例如)Spotify的iOS应用程序(如左边底部的一面

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

or as in this

还是在这

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

I have tried to drag a Container View into my Navigation controller (in which my TableViewCell is embedded), but it won't let me drop it there.

我曾尝试将容器视图拖放到导航控制器中(其中嵌入了TableViewCell),但它不允许我将它放到那里。

It looks like I can drag the Container View into my TableView, but then how would it remain there when i navigate between tableviews?

看起来我可以把容器视图拖到我的TableView中,但是当我在TableView中导航的时候,它怎么还在那里呢?

Trying to follow @Rintaro's suggestion, but I'm a little new to XCode. How did you do this? So I made a single view application, i added a container view to the first VC, it's imm drawing it somewhere else in the storyboard, but i can't figure out how to tell that view that it's a navigation controller. also, as soon as i add a second container to the first VC and tried to size it, the first container disappears! It is still listed in the hierarchy on the left, and still has an arrow pointing out of it, but the view controller that was added and was being pointed to is also invisible?!

尝试遵循@Rintaro的建议,但是我对XCode有点陌生。你是怎么做到的?我做了一个单独的视图应用,我在第一个VC中添加了一个容器视图,它是imm在故事板的其他地方绘制的,但是我不知道如何告诉那个视图它是一个导航控制器。而且,一旦我在第一个VC中添加第二个容器并尝试对它进行大小设置,第一个容器就会消失!它仍然在左边的层次结构中列出,并且仍然有一个箭头指向它,但是添加并被指向的视图控制器也是不可见的吗?

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

UPDATE: This works very well, but it has a problem with orientation changes. how can i make this work in both orientations? (I hypothesize that it currently positions the "nowplaying view" off screen when the orientation changes).

更新:这个功能很好,但是它存在方向改变的问题。我如何使这两个方向都工作?(我假设当方向改变时,它会将“现在播放视图”移出屏幕)。

4 个解决方案

#1


19  

Basically, view hierarchy like that is constructed like this:

基本上,像这样的视图层级结构是这样构建的:

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

Using two "Container View" in initial view controller, one for Navigation Controller, one for "Now Playing Bar" view controller.

在初始视图控制器中使用两个“容器视图”,一个用于导航控制器,一个用于“现在播放栏”视图控制器。

ADDED:

补充道:

"Main Container View Controller" would be your own UIViewController subclass. It will have responsibility to show/hide "Now Playing Bar".

"主容器视图控制器"将是你自己的UIViewController子类。它将有责任显示/隐藏“现在玩吧”。


Workaround for Interface Builder strange behaviors.

为接口生成器的奇怪行为而变通。

You can set Auto Layout constraints like following. Maybe you might want to select the view from the left menu.

您可以设置如下的自动布局约束。也许你想从左菜单中选择视图。

Note that, you should uncheck Constrain to margins check box.

注意,您应该将约束取消到页边复选框。

Container View for Navigation Controller:

导航控制器的容器视图:

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

Container View for Now Playing Bar Controller:

现在播放栏控制器的容器视图:

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

And then, Update Frames from the menu:

然后,从菜单中更新帧:

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

#2


2  

If you are manually placing any buttons with absolute coordinates, make sure that you update the coordinates of them when the rotation is changed.

如果您手动放置任何具有绝对坐标的按钮,请确保在更改旋转时更新它们的坐标。

#3


0  

Obviously you need to create a custom UIView class, where you will show this menu. And when you will create it, add it to your view just like here:

显然,您需要创建一个自定义的UIView类,您将在其中显示这个菜单。当你创建它的时候,把它添加到你的视图中,就像这样:

float y = ROOTVC.view.frame.size.height - 49;
[self setFrame:CGRectMake(0, y, 320, 49)];
[ROOTVC.view addSubview:self];
[ROOTVC.view bringSubviewToFront:self];

#4


0  

I would simply add a nowPlayingView to the appDelegate.window and adjust either:

我只需向appDelegate添加一个nowPlayingView。窗口和调整:

  • The window.rootController.view frame to avoid overlapping the nowPlayingView.

    window.rootController。视图框架避免重叠当前播放视图。

  • If window.rootController.view is a UIScrollView, adjust its contentInset.bottom to avoid overlapping the nowPlayingView. You can also use transparency/translucency with this solution.

    如果window.rootController。视图是一个UIScrollView,调整它的contentInset。底部,以避免重叠的nowPlayingView。您还可以在此解决方案中使用透明度/半透明。

  • Add a dummy toolbar to the controller that will get covered by the nowPlayingView.

    向控制器添加一个虚拟工具栏,由nowPlayingView覆盖。

If your window.rootController is a UINavigationController, then you have to probably do the above fore each controller you push. The nowPlayingView will stay unchanged on top.

如果你的窗口。rootController是一个UINavigationController,那么您可能需要在每次推送控制器之前执行上述操作。现在播放视图将保持顶部不变。

#1


19  

Basically, view hierarchy like that is constructed like this:

基本上,像这样的视图层级结构是这样构建的:

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

Using two "Container View" in initial view controller, one for Navigation Controller, one for "Now Playing Bar" view controller.

在初始视图控制器中使用两个“容器视图”,一个用于导航控制器,一个用于“现在播放栏”视图控制器。

ADDED:

补充道:

"Main Container View Controller" would be your own UIViewController subclass. It will have responsibility to show/hide "Now Playing Bar".

"主容器视图控制器"将是你自己的UIViewController子类。它将有责任显示/隐藏“现在玩吧”。


Workaround for Interface Builder strange behaviors.

为接口生成器的奇怪行为而变通。

You can set Auto Layout constraints like following. Maybe you might want to select the view from the left menu.

您可以设置如下的自动布局约束。也许你想从左菜单中选择视图。

Note that, you should uncheck Constrain to margins check box.

注意,您应该将约束取消到页边复选框。

Container View for Navigation Controller:

导航控制器的容器视图:

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

Container View for Now Playing Bar Controller:

现在播放栏控制器的容器视图:

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

And then, Update Frames from the menu:

然后,从菜单中更新帧:

我如何在iOS中使用XCode在媒体播放器应用程序中使用类似的工具?

#2


2  

If you are manually placing any buttons with absolute coordinates, make sure that you update the coordinates of them when the rotation is changed.

如果您手动放置任何具有绝对坐标的按钮,请确保在更改旋转时更新它们的坐标。

#3


0  

Obviously you need to create a custom UIView class, where you will show this menu. And when you will create it, add it to your view just like here:

显然,您需要创建一个自定义的UIView类,您将在其中显示这个菜单。当你创建它的时候,把它添加到你的视图中,就像这样:

float y = ROOTVC.view.frame.size.height - 49;
[self setFrame:CGRectMake(0, y, 320, 49)];
[ROOTVC.view addSubview:self];
[ROOTVC.view bringSubviewToFront:self];

#4


0  

I would simply add a nowPlayingView to the appDelegate.window and adjust either:

我只需向appDelegate添加一个nowPlayingView。窗口和调整:

  • The window.rootController.view frame to avoid overlapping the nowPlayingView.

    window.rootController。视图框架避免重叠当前播放视图。

  • If window.rootController.view is a UIScrollView, adjust its contentInset.bottom to avoid overlapping the nowPlayingView. You can also use transparency/translucency with this solution.

    如果window.rootController。视图是一个UIScrollView,调整它的contentInset。底部,以避免重叠的nowPlayingView。您还可以在此解决方案中使用透明度/半透明。

  • Add a dummy toolbar to the controller that will get covered by the nowPlayingView.

    向控制器添加一个虚拟工具栏,由nowPlayingView覆盖。

If your window.rootController is a UINavigationController, then you have to probably do the above fore each controller you push. The nowPlayingView will stay unchanged on top.

如果你的窗口。rootController是一个UINavigationController,那么您可能需要在每次推送控制器之前执行上述操作。现在播放视图将保持顶部不变。