Music_Player3/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Base(基类,导航栏,标签栏)/MPPositive_TabBarController.swift

228 lines
11 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// MPPositive_TabBarController.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/4/19.
//
import UIKit
///btabBar
class MPPositive_TabBarController: UITabBarController, UIViewControllerTransitioningDelegate, GADFullScreenContentDelegate {
//tabBar
private lazy var customTabBar:MPPositive_CustomTabBar = .init(frame: .init(x: 0, y: 0, width: screen_Width, height: 72*width))
private lazy var bottomView:MPPositive_BottomShowView = .init(frame: .init(x: 0, y: 0, width: 351, height: 82))
//
private var isbottomShow:Bool = false{
willSet{
if isbottomShow != newValue {
switch_bottomShowAnimation(newValue)
}
}
}
//Push
private var isPush:Bool = false
override func viewDidLoad() {
super.viewDidLoad()
self.setValue(customTabBar, forKey: "tabBar")
//
let homeVC = MPPositive_NavigationController(rootViewController: MPPositive_HomeViewController())
let searchVC = MPPositive_NavigationController(rootViewController: MPPositive_SearchViewController())
let libraryVC = MPPositive_NavigationController(rootViewController: MPPositive_LibraryViewController())
viewControllers = [homeVC,searchVC,libraryVC]
//tabBaritem
tabBar.items?.forEach({ item in
item.isEnabled = false
})
tabBar.barTintColor = .clear
UITabBar.appearance().backgroundColor = .clear
tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()
//View
view.addSubview(bottomView)
//View
bottomView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.bottom.equalToSuperview().offset(82*width)
make.width.equalTo(351*width)
make.height.equalTo(82*width)
}
bottomView.showListBlock = {
[weak self] in
if MP_PlayerManager.shared.loadPlayer != nil {
MPPositive_ModalType = .PlayerList
let listVC = MPPositive_PlayerListShowViewController()
listVC.transitioningDelegate = self
listVC.modalPresentationStyle = .custom
self?.present(listVC, animated: true)
}
}
bottomView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(playerClick(_ :))))
addNotification()
}
//
private func addNotification() {
//
NotificationCenter.notificationKey.add(observer: self, selector: #selector(switchAction(_:)), notificationName: .switch_tabBarItem)
//
NotificationCenter.notificationKey.add(observer: self, selector: #selector(pupPlayerAction), notificationName: .pup_player_vc)
NotificationCenter.notificationKey.add(observer: self, selector: #selector(bottomAnimationAction(_:)), notificationName: .pup_bottom_show)
NotificationCenter.notificationKey.add(observer: self, selector: #selector(bottomAnimationAction(_:)), notificationName: .player_delete_list)
NotificationCenter.notificationKey.add(observer: self, selector: #selector(pushAction(_ :)), notificationName: .positive_nav_push)
NotificationCenter.notificationKey.add(observer: self, selector: #selector(popAction(_ :)), notificationName: .positive_nav_pop)
}
deinit {
//
NotificationCenter.default.removeObserver(self)
}
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return MPPositive_PresentationController(presentedViewController: presented, presenting: presenting)
}
}
//MARK: -
extension MPPositive_TabBarController {
//
@objc private func switchAction(_ sender:Notification) {
let tag = sender.object as! Int
selectedIndex = tag
}
@objc private func playerClick(_ sender:UITapGestureRecognizer) {
MP_AnalyticsManager.shared.song_clickAction("Player")
pupPlayerAction()
}
//player
@objc private func pupPlayerAction() {
MP_AdMobManager.shared.showPlayInterstitialAdIfAvailable { [weak self] ad in
guard let self = self else {return}
//
MP_AdMobManager.shared.isShowingPlayInterstitialAd = true
//广
MP_AdMobManager.shared.setInterstitialSwitch(true)
ad.fullScreenContentDelegate = self
ad.present(fromRootViewController: self)
}
//
DispatchQueue.main.async {
[weak self] in
let playerVC = MPPositive_PlayerViewController()
playerVC.modalPresentationStyle = .fullScreen
playerVC.recommendBlock = {
let recommendVC = MPPositive_RecommendViewController(MP_PlayerManager.shared.loadPlayer?.currentVideo?.song.relatedID ?? "")
self?.viewControllers![self?.selectedIndex ?? 0].children[0].navigationController?.pushViewController(recommendVC, animated: false)
}
playerVC.searchBlock = { (text) in
let resultVC = MPPositive_SearchResultShowViewController(text, isShowAd: false)
self?.viewControllers![self?.selectedIndex ?? 0].children[0].navigationController?.pushViewController(resultVC, animated: false)
}
self?.present(playerVC, animated: true)
}
}
//
@objc private func bottomAnimationAction(_ sender:Notification) {
isbottomShow = MP_PlayerManager.shared.loadPlayer != nil
}
//BottomView
private func switch_bottomShowAnimation(_ state:Bool) {
UIView.animate(withDuration: 0.3) {
[weak self] in
guard let self = self else { return }
if state {
//
bottomView.transform = .init(translationX: 0, y: isPush ? -82*width:-145*width)
}else {
//
bottomView.transform = .identity
}
}
}
//push
@objc private func pushAction(_ sender:Notification) {
isPush = true
//
if isbottomShow == true {
//bottomView83
UIView.animate(withDuration: 0.3) {
[weak self] in
guard let self = self else { return }
bottomView.transform = .init(translationX: 0, y: -82*width)
}
}
}
@objc private func popAction(_ sender:Notification) {
isPush = false
//
if isbottomShow == true {
//bottomView83
UIView.animate(withDuration: 0.3) {
[weak self] in
guard let self = self else { return }
bottomView.transform = .init(translationX: 0, y: -145*width)
}
}
}
//MARK: - 广 GADFullScreenContentDelegate
//广
func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
// UIApplication.shared.isStatusBarHidden = true
if ad === MP_AdMobManager.shared.playInterstitialAd {//广
print("当前展示的广告是播放插页广告广告ID--\(MP_AdMobManager.shared.playInterstitialAd?.adUnitID ?? "")")
MP_AdMobManager.shared.playInterstitialAd?.paidEventHandler = { adValue in
if let response = MP_AdMobManager.shared.playInterstitialAd?.responseInfo {
MP_AnalyticsManager.shared.play_ads_showSuccessAction(response, adValue: adValue)
}
}
}
}
//广
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
// UIApplication.shared.isStatusBarHidden = false
MP_AdMobManager.shared.interstitialDate = Date()
if ad === MP_AdMobManager.shared.playInterstitialAd {//广
let UUID = MP_AdMobManager.shared.playInterstitialAd?.adUnitID ?? ""
print("当前消失的广告是播放插页广告广告ID--\(UUID)")
//广
if MP_AdMobManager.shared.completePlayInterstitialAdBlock != nil {
MP_AdMobManager.shared.completePlayInterstitialAdBlock!()
}
//
DispatchQueue.main.async {
[weak self] in
let playerVC = MPPositive_PlayerViewController()
playerVC.modalPresentationStyle = .fullScreen
playerVC.recommendBlock = {
let recommendVC = MPPositive_RecommendViewController(MP_PlayerManager.shared.loadPlayer.currentVideo.song.relatedID)
self?.viewControllers![self?.selectedIndex ?? 0].children[0].navigationController?.pushViewController(recommendVC, animated: false)
}
self?.present(playerVC, animated: true)
}
}
}
//广
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
// UIApplication.shared.isStatusBarHidden = false
MP_AdMobManager.shared.interstitialDate = Date()
if ad === MP_AdMobManager.shared.playInterstitialAd {//广
let UUID = MP_AdMobManager.shared.playInterstitialAd?.adUnitID ?? ""
print("播放插页广告展示时出错广告ID--\(UUID),具体错误原因:\(error.localizedDescription)")
MP_AnalyticsManager.shared.play_ads_showFailureAction(error.localizedDescription)
//广
if MP_AdMobManager.shared.completePlayInterstitialAdBlock != nil {
MP_AdMobManager.shared.completePlayInterstitialAdBlock!()
}
// //
// DispatchQueue.main.async {
// [weak self] in
// let playerVC = MPPositive_PlayerViewController()
// playerVC.modalPresentationStyle = .fullScreen
// playerVC.recommendBlock = {
// let recommendVC = MPPositive_RecommendViewController(MP_PlayerManager.shared.loadPlayer.currentVideo.song.relatedID)
// self?.viewControllers![self?.selectedIndex ?? 0].children[0].navigationController?.pushViewController(recommendVC, animated: false)
// }
// self?.present(playerVC, animated: true)
// }
}
}
}