How do I make a now playing bar like in media player apps in iOS with XCode?

旧时模样 提交于 2019-12-02 18:53:13

Basically, view hierarchy like that is constructed like this:

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".


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:

Container View for Now Playing Bar Controller:

And then, Update Frames from the menu:

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

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:

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

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

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

  • 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.

  • Add a dummy toolbar to the controller that will get covered by the 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!