tabbar & playerBar setup is complete

dev
wenlei 1 year ago
parent 6a0b827eac
commit d8493e0767

@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
3C955224FAC6473657A027C3 /* Pods_IndieMusicTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42CE866330C1741ADEC950B2 /* Pods_IndieMusicTests.framework */; };
49330FC1492387B5155757F6 /* Pods_IndieMusic_IndieMusicUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA03C869C12FEE5FB3D835C2 /* Pods_IndieMusic_IndieMusicUITests.framework */; };
7743999E2AFA18C3006F8EEA /* PlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7743999D2AFA18C3006F8EEA /* PlayerViewController.swift */; };
774399A02AFA1968006F8EEA /* PlayerTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7743999F2AFA1968006F8EEA /* PlayerTabBar.swift */; };
778B8A212AF8E36D0034AFD4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 778B8A202AF8E36D0034AFD4 /* AppDelegate.swift */; };
778B8A232AF8E36D0034AFD4 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 778B8A222AF8E36D0034AFD4 /* SceneDelegate.swift */; };
778B8A282AF8E36D0034AFD4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 778B8A262AF8E36D0034AFD4 /* Main.storyboard */; };
@ -91,6 +93,8 @@
3BA421D41748C113CCE36A32 /* Pods_IndieMusic.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_IndieMusic.framework; sourceTree = BUILT_PRODUCTS_DIR; };
42CE866330C1741ADEC950B2 /* Pods_IndieMusicTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_IndieMusicTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
69F724137B8F9C1F7E51080D /* Pods-IndieMusicTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-IndieMusicTests.release.xcconfig"; path = "Target Support Files/Pods-IndieMusicTests/Pods-IndieMusicTests.release.xcconfig"; sourceTree = "<group>"; };
7743999D2AFA18C3006F8EEA /* PlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerViewController.swift; sourceTree = "<group>"; };
7743999F2AFA1968006F8EEA /* PlayerTabBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerTabBar.swift; sourceTree = "<group>"; };
778B8A1D2AF8E36D0034AFD4 /* IndieMusic.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = IndieMusic.app; sourceTree = BUILT_PRODUCTS_DIR; };
778B8A202AF8E36D0034AFD4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
778B8A222AF8E36D0034AFD4 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@ -185,6 +189,15 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
7743999C2AFA18B0006F8EEA /* Player */ = {
isa = PBXGroup;
children = (
7743999D2AFA18C3006F8EEA /* PlayerViewController.swift */,
7743999F2AFA1968006F8EEA /* PlayerTabBar.swift */,
);
path = Player;
sourceTree = "<group>";
};
778B8A142AF8E36D0034AFD4 = {
isa = PBXGroup;
children = (
@ -328,6 +341,7 @@
778B8A582AF8EAED0034AFD4 /* Modules */ = {
isa = PBXGroup;
children = (
7743999C2AFA18B0006F8EEA /* Player */,
778B8A762AF8ECE50034AFD4 /* Home */,
778B8A722AF8ECE50034AFD4 /* Login */,
778B8A732AF8ECE50034AFD4 /* Mine */,
@ -734,6 +748,7 @@
778B8A712AF8ECD30034AFD4 /* Api.swift in Sources */,
778B8A812AF8ECE50034AFD4 /* HomeTabBarViewModel.swift in Sources */,
778B8AC02AF8ED280034AFD4 /* ViewController.swift in Sources */,
774399A02AFA1968006F8EEA /* PlayerTabBar.swift in Sources */,
778B8A902AF8ECF20034AFD4 /* Token.swift in Sources */,
778B8A6B2AF8ECD30034AFD4 /* IndieMusicAPI.swift in Sources */,
778B8A622AF8ECC20034AFD4 /* ErrorTracker.swift in Sources */,
@ -749,6 +764,7 @@
778B8A6E2AF8ECD30034AFD4 /* RestApi.swift in Sources */,
778B8ABC2AF8ED280034AFD4 /* PresentationController.swift in Sources */,
778B8AAA2AF8ED0E0034AFD4 /* AVPlayer.swift in Sources */,
7743999E2AFA18C3006F8EEA /* PlayerViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -48,6 +48,8 @@ final class Application: NSObject {
let viewModel = HomeTabBarViewModel(authorized: authorized, provider: provider)
// self?.navigator.show(segue: .tabs(viewModel: viewModel), sender: nil, transition: .root(in: window))
// window.rootViewController = IndieMusicViewController.init(viewModel: <#T##ViewModel?#>, navigator: <#T##Navigator#>)
// window.makeKeyAndVisible()
self?.navigator.show(segue: .tabs(viewModel: viewModel), sender: nil, transition: .root(in: window))
}

@ -43,10 +43,15 @@ class Navigator {
switch segue {
case .tabs(let viewModel):
let rootVC = HomeTabBarController(viewModel: viewModel, navigator: self)
// let rootVC = IndieMusicViewController(viewModel: viewModel, navigator: self)
let home = HomeViewController(viewModel: viewModel, navigator: self)
let search = SearchViewController(viewModel: viewModel, navigator: self)
let mine = MineViewController(viewModel: viewModel, navigator: self)
// rootVC.setViewController([home, search, mine])
rootVC.viewControllers = [home, search, mine]
return rootVC

@ -88,7 +88,7 @@ extension NavigationController {
override func pushViewController(_ viewController: UIViewController, animated: Bool)
{
if !children.isEmpty {
viewController.hidesBottomBarWhenPushed = true
// viewController.hidesBottomBarWhenPushed = true
// let leftButton = UIButton.init()
// leftButton.setTitle("", for: .normal)

@ -55,15 +55,38 @@ enum HomeTabBarItem: Int {
let vc = controller(with: viewModel, navigator: navigator)
let item = UITabBarItem.init(title: nil, image: image, selectedImage: selectedImage)
item.tag = rawValue
item.imageInsets = UIEdgeInsets(top: 10, left: 0, bottom: -10, right: 0)
vc.tabBarItem = item
return vc
}
}
class HomeTabBarController: UITabBarController, Navigatable {
var viewModel: HomeTabBarViewModel?
var navigator: Navigator!
var customeTabBar: UITabBar = {
let tabBar = UITabBar.init()
return tabBar
}()
var playerTabBar: PlayerTabBar = {
let playerTabBar = PlayerTabBar.init()
playerTabBar.isHidden = true
return playerTabBar
}()
private(set) public var isPlayerBarShowing = false
private(set) public var isTabBarShowing = true
private var isAnimating = false
init(viewModel: ViewModel?, navigator: Navigator) {
self.viewModel = viewModel as? HomeTabBarViewModel
@ -84,9 +107,29 @@ class HomeTabBarController: UITabBarController, Navigatable {
}
func makeUI() {
tabBar.backgroundColor = .white
tabBar.isHidden = true
view.addSubview(playerTabBar)
view.addSubview(customeTabBar)
customeTabBar.snp.makeConstraints { make in
make.left.equalTo(view)
make.right.equalTo(view)
make.bottom.equalTo(view)
make.height.equalTo(BaseDimensions.tabBarHeight)
}
playerTabBar.snp.makeConstraints { make in
make.left.equalTo(view)
make.right.equalTo(view)
make.bottom.equalTo(customeTabBar.snp.top).offset(BaseDimensions.tabBarHeight)
}
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
tabBar.tintColor = .black
}
@ -104,4 +147,128 @@ class HomeTabBarController: UITabBarController, Navigatable {
}).disposed(by: rx.disposeBag)
}
override func setViewControllers(_ viewControllers: [UIViewController]?, animated: Bool) {
guard let viewControllers = viewControllers else { return }
super.setViewControllers(viewControllers, animated: animated)
var tabItems = [UITabBarItem]()
for (index, viewController) in viewControllers.enumerated() {
var tabItem: UITabBarItem = viewController.tabBarItem
if tabItem.title == nil && tabItem.image == nil && tabItem.selectedImage == nil {
tabItem = UITabBarItem(title: "", image: nil, tag: index)
}
tabItems.append(tabItem)
}
customeTabBar.setItems(tabItems, animated: false)
customeTabBar.selectedItem = customeTabBar.items?.first
}
open func showTabBar(_ isShowing: Bool, animated: Bool) {
if isAnimating { return }
isAnimating = true
if isShowing {
customeTabBar.isHidden = false
customeTabBar.snp.remakeConstraints { make in
make.left.equalTo(view)
make.right.equalTo(view)
make.bottom.equalTo(view)
make.height.equalTo(BaseDimensions.tabBarHeight)
}
} else {
customeTabBar.snp.remakeConstraints { make in
make.left.equalTo(view)
make.right.equalTo(view)
make.bottom.equalTo(view).offset(self.tabBar.bounds.height)
make.height.equalTo(BaseDimensions.tabBarHeight)
}
}
var animationDuration = 0.3
if animated == false {
animationDuration = 0
}
UIView.animate(withDuration: animationDuration,
delay: 0,
usingSpringWithDamping: 0.7,
initialSpringVelocity: 0.25,
options: .curveEaseInOut,
animations: {
if isShowing {
self.customeTabBar.alpha = 1
} else {
self.customeTabBar.alpha = 0
}
self.view.layoutIfNeeded()
}) { (completed) in
self.isTabBarShowing = isShowing
self.customeTabBar.isHidden = !isShowing
self.isAnimating = false
}
}
open func showPlayerBar(_ isShowing: Bool, animated: Bool) {
if isAnimating { return }
isAnimating = true
if isShowing {
playerTabBar.isHidden = false
playerTabBar.snp.remakeConstraints { make in
make.left.equalTo(view)
make.right.equalTo(view)
make.bottom.equalTo(customeTabBar.snp.top)
}
} else {
playerTabBar.snp.remakeConstraints { make in
make.left.equalTo(view)
make.right.equalTo(view)
make.bottom.equalTo(customeTabBar.snp.top).offset(BaseDimensions.tabBarHeight)
}
}
var animationDuration = 0.3
if animated == false {
animationDuration = 0
}
UIView.animate(withDuration: animationDuration,
delay: 0,
usingSpringWithDamping: 0.7,
initialSpringVelocity: 0.25,
options: .curveEaseInOut,
animations: {
if isShowing {
self.playerTabBar.alpha = 1
} else {
self.playerTabBar.alpha = 0
}
self.view.layoutIfNeeded()
}) { (completed) in
self.isPlayerBarShowing = isShowing
self.playerTabBar.isHidden = !isShowing
self.isAnimating = false
}
}
}

@ -8,21 +8,93 @@
import UIKit
class HomeViewController: ViewController {
var button: UIButton = {
let button = UIButton.init()
button.setTitle("button 1", for: .normal)
button.backgroundColor = .red
button.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
return button
}()
var button2: UIButton = {
let button = UIButton.init()
button.setTitle("button 2", for: .normal)
button.backgroundColor = .blue
button.addTarget(self, action: #selector(buttonClick2), for: .touchUpInside)
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.navigationTitle = "123"
}
override func makeUI() {
super.makeUI()
view.backgroundColor = .white
view.addSubview(button)
view.addSubview(button2)
}
override func bindViewModel() {
super.bindViewModel()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
button.snp.makeConstraints { make in
make.centerX.equalTo(view)
make.centerY.equalTo(view).offset(-100)
make.size.equalTo(CGSize.init(width: 100, height: 100))
}
button2.snp.makeConstraints { make in
make.centerX.equalTo(view)
make.centerY.equalTo(view).offset(100)
make.size.equalTo(CGSize.init(width: 100, height: 100))
}
}
@objc func buttonClick() {
// guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
//
//
// if let tabbar = UIApplication.shared.windows.first?.rootViewController as? IndieMusicViewController {
// tabbar.showTabBar(!tabbar.isTabBarShowing, animated: true)
// }
//
if let tabbar = self.tabBarController as? HomeTabBarController {
tabbar.showTabBar(!tabbar.isTabBarShowing, animated: true)
}
}
@objc func buttonClick2() {
if let tabbar = self.tabBarController as? HomeTabBarController {
tabbar.showPlayerBar(!tabbar.isPlayerBarShowing, animated: true)
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
hidesBottomBarWhenPushed = false
let vc = PlayerViewController.init(viewModel: viewModel, navigator: navigator)
vc.view.backgroundColor = .white
self.navigationController?.pushViewController(vc, animated: true)
// self.present(vc, animated: true)
}
}

@ -16,14 +16,9 @@ class MineViewController: ViewController {
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
override func makeUI() {
super.makeUI()
view.backgroundColor = .blue
}
*/
}

@ -0,0 +1,137 @@
//
// PlayerBarView.swift
// IndieMusic
//
// Created by WenLei on 2023/11/7.
//
import UIKit
class PlayerTabBar: UIView {
private var coverView: UIImageView = {
var coverView = UIImageView.init()
coverView.backgroundColor = .red
return coverView
}()
private var containerView: UIView = {
var containerView = UIView.init()
containerView.backgroundColor = .white
return containerView
}()
private var titleLabel: UILabel = {
var titleLabel = UILabel.init()
return titleLabel
}()
private var artistLabel: UILabel = {
var artistLabel = UILabel.init()
return artistLabel
}()
private var playButton: UIButton = {
var playButton = UIButton.init()
playButton.setImage(UIImage.init(named: "playerBar_play_btn"), for: .normal)
return playButton
}()
private var listButton: UIButton = {
var listButton = UIButton.init()
listButton.setImage(UIImage.init(named: "playerBar_list_btn"), for: .normal)
return listButton
}()
private var progressView: UIProgressView = {
var progressView = UIProgressView.init()
return progressView
}()
override init(frame: CGRect) {
super.init(frame: frame)
makeUI()
titleLabel.text = "测试标题"
artistLabel.text = "测试"
progressView.progress = 0.25
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func makeUI() {
containerView.addSubview(titleLabel)
containerView.addSubview(artistLabel)
containerView.addSubview(playButton)
containerView.addSubview(listButton)
addSubview(containerView)
addSubview(progressView)
addSubview(coverView)
}
override func layoutSubviews() {
super.layoutSubviews()
coverView.snp.remakeConstraints { make in
make.left.equalTo(self).offset(30)
make.top.equalTo(self).offset(0)
make.size.equalTo(CGSize.init(width: 52, height: 52))
make.bottom.equalTo(self).offset(-14)
}
containerView.snp.makeConstraints { make in
make.left.equalTo(self)
make.right.equalTo(self)
make.bottom.equalTo(self)
make.height.equalTo(54)
}
listButton.snp.makeConstraints { make in
make.right.equalTo(containerView).offset(-30)
make.centerY.equalTo(containerView)
make.size.equalTo(CGSize.init(width: 24, height: 24))
}
playButton.snp.makeConstraints { make in
make.right.equalTo(listButton.snp.left).offset(-18)
make.centerY.equalTo(containerView)
make.size.equalTo(CGSize.init(width: 24, height: 24))
}
titleLabel.snp.makeConstraints { make in
make.top.equalTo(containerView).offset(5)
make.left.equalTo(coverView.snp.right).offset(11)
make.right.equalTo(playButton.snp.left).offset(-10)
}
artistLabel.snp.makeConstraints { make in
make.top.equalTo(titleLabel.snp.bottom)
make.left.equalTo(coverView.snp.right).offset(11)
make.right.equalTo(playButton.snp.left).offset(-10)
}
progressView.snp.makeConstraints { make in
make.left.equalTo(self).offset(30)
make.right.equalTo(self).offset(-30)
make.bottom.equalTo(self)
make.height.equalTo(2)
}
}
}

@ -0,0 +1,43 @@
//
// PlayerViewController.swift
// IndieMusic
//
// Created by WenLei on 2023/11/7.
//
import UIKit
class PlayerViewController: ViewController {
override func viewDidLoad() {
super.viewDidLoad()
// hidesBottomBarWhenPushed = false
self.navigationTitle = "1234"
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let tabbar = self.tabBarController as? HomeTabBarController {
}
//
// let vc = MineViewController.init(viewModel: viewModel, navigator: navigator)
//
// self.present(vc, animated: true)
// UIView.animate(withDuration: 0.3) {
// self.tabBarController?.tabBar.isHidden.toggle()
// }
}
}

@ -12,7 +12,7 @@ class SearchViewController: ViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = .red
}

@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "playerBar_list_btn.svg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,6 @@
<svg width="20" height="16" viewBox="0 0 20 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M19 1H1" stroke="#37373D" style="stroke:#37373D;stroke:color(display-p3 0.2157 0.2157 0.2392);stroke-opacity:1;" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19 7H1" stroke="#37373D" style="stroke:#37373D;stroke:color(display-p3 0.2157 0.2157 0.2392);stroke-opacity:1;" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M11 13H1" stroke="#37373D" style="stroke:#37373D;stroke:color(display-p3 0.2157 0.2157 0.2392);stroke-opacity:1;" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M19.2854 12.5713C19.6091 12.7655 19.6091 13.2345 19.2854 13.4287L15.7572 15.5457C15.424 15.7456 15 15.5056 15 15.1169V10.8831C15 10.4944 15.424 10.2544 15.7572 10.4543L19.2854 12.5713Z" fill="#37373D" style="fill:#37373D;fill:color(display-p3 0.2157 0.2157 0.2392);fill-opacity:1;"/>
</svg>

After

Width:  |  Height:  |  Size: 1007 B

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "playerBar_play_btn.svg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,3 @@
<svg width="15" height="18" viewBox="0 0 15 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.4505 8.12842C15.1302 8.51073 15.1302 9.48927 14.4505 9.87158L1.49026 17.1617C0.823658 17.5367 0 17.055 0 16.2902L0 1.70985C0 0.94502 0.823657 0.463307 1.49026 0.838272L14.4505 8.12842Z" fill="#AD3030" style="fill:#AD3030;fill:color(display-p3 0.6784 0.1882 0.1882);fill-opacity:1;"/>
</svg>

After

Width:  |  Height:  |  Size: 440 B

Loading…
Cancel
Save