![](/img/trans.png)
[英]How can I implement the side alphabetic view in apple's music app in swift? Which used to sort the items in the list in alphabetic order
[英]How can I implement the miniplayer in Apple Music in my own app?
Apple 在 iOS 8.4 上的 Apple Music 中引入了新的 UI。
当一个音轨开始播放时,一个迷你播放器会出现在标签栏的正上方,通过向上拖动或点击它可以进入全屏模式。
我想这是使用 UIViewController 包含 API。 我可以从哪里开始我自己的实现?
我该如何实现类似的东西?
有趣的是,我在本周早些时候遇到了一个框架,它实现了这个。 看看LNPopupController 。 它实现了您正在寻找的行为(显示一个迷你栏,然后点击或拖动以显示一个视图控制器)。 如果它不太适合您的需求,也许它至少可以为您实现自己的东西提供一个起点。
在您的根视图控制器中添加一个容器视图,用于 Apple Music uiTabBar
控制器。
func configureContainer() {
// add container
containerView = UIView()
containerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(containerView)
let g = view.safeAreaLayoutGuide
NSLayoutConstraint.activate([
containerView.leadingAnchor.constraint(equalTo: g.leadingAnchor),
containerView.trailingAnchor.constraint(equalTo: g.trailingAnchor),
containerView.bottomAnchor.constraint(equalTo: tabBar.topAnchor),
containerView.heightAnchor.constraint(equalToConstant: 64.0)
])
// add child view controller view to container
miniPlayer = MiniPlayerViewController()
guard let miniPlayer = miniPlayer else { return }
addChild(miniPlayer)
miniPlayer.view.translatesAutoresizingMaskIntoConstraints = false
containerView.addSubview(miniPlayer.view)
// Create and activate the constraints for the child’s view.
guard let miniPlayerView = miniPlayer.view else { return }
NSLayoutConstraint.activate([
miniPlayerView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
miniPlayerView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor),
miniPlayerView.topAnchor.constraint(equalTo: containerView.topAnchor),
miniPlayerView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor),
])
miniPlayer.didMove(toParent: self)
}
就我而言,我想将miniPlayer
隐藏在一个特定的 VC 中,因此我使用 NotificationCenter 来做到这一点。 在根视图控制器中注册通知。
NotificationCenter.default.addObserver(self, selector: #selector(miniPlayerVisibilityNeedsChange(notify:)), name: NSNotification.Name("miniPlayerVisibilityNeedsToBeUpdate"), object: nil)
将其发布在您的特定 VC 中,就是这样!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// hide miniPlayer for this vc
NotificationCenter.default.post(name: NSNotification.Name("miniPlayerVisibilityNeedsToBeUpdate"), object: false)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// show miniPlayer again when leaving this vc
NotificationCenter.default.post(name: NSNotification.Name("miniPlayerVisibilityNeedsToBeUpdate"), object: true)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.