LoginSignup
7
7

More than 5 years have passed since last update.

iOS標準のmusicアプリのようなプレイヤーを出せるLNPopupControllerの紹介

Last updated at Posted at 2017-01-17

概要

デフォルトのmusicアプリのように、tabbarの上部にviewを追加してごにょごにょできるライブラリを探していたら、あったのでその紹介とその使い方について紹介。

LNPopupController

実例

今回の要件は下記のようなもの

  • タブバーアプリで動作する。
  • 再生部分のビューをタブバーのすぐ上に配置する。
  • タブを切り替えてもそのビューはタブバーに属したものとして表示される

要は、iOSデフォルトの音楽アプリのような挙動を目指した。

実装後は下のGIFのようになる。

output.gif

 使い方

下記のコードをタブバー内の任意のViewController内で実行すれば良い。
customBarViewControllerに設定するViewControllerはLNPopupCustomBarViewControllerを継承している必要がある。

example
let player:PlayerVC = PlayerVC()
tabBarController?.popupBar.customBarViewController = player
tabBarController?.popupBar.barStyle = .prominent
tabBarController?.presentPopupBar(withContentViewController: UIViewController(), animated: true, completion: nil)

デフォルトでは、tabbarの直上に出るバーに対してタップなどを行うとpresentPopupBarに指定したViewControllerを表示するようになっている。
そういった動作を抑制したい時は、customBarViewControllerに設定したViewControllerにてwantsDefaultTapGestureRecognizerプロパティをfalseにすればよい。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7