tabbar开发

This commit is contained in:
zjx 2025-05-20 10:34:39 +08:00
parent 679bd0e392
commit 54b5f08e23
53 changed files with 394 additions and 63 deletions

12
Podfile
View File

@ -1,7 +1,17 @@
# Uncomment the next line to define a global platform for your project
source 'https://github.com/CocoaPods/Specs.git'
#source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '15.6'
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
config.build_settings['EXCLUDED_ARCHITECTURES'] = 'i386'
end
end
end
target 'Veloria' do
use_frameworks!

View File

@ -11,7 +11,9 @@ PODS:
- Moya/Core (= 15.0.0)
- Moya/Core (15.0.0):
- Alamofire (~> 5.0)
- SmartCodable (4.3.9)
- SmartCodable (5.0.9):
- SmartCodable/Core (= 5.0.9)
- SmartCodable/Core (5.0.9)
- SnapKit (5.7.1)
- Toast (4.1.1)
- YYKit (1.0.9):
@ -35,7 +37,7 @@ DEPENDENCIES:
- ZFPlayer/AVPlayer
SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
trunk:
- Alamofire
- CocoaAsyncSocket
- ESTabBarController-swift
@ -59,12 +61,12 @@ SPEC CHECKSUMS:
KTVHTTPCache: 5711692cdf9a5ecfe829b1e16577deb3ffe3dc86
MJRefresh: ff9e531227924c84ce459338414550a05d2aea78
Moya: 138f0573e53411fb3dc17016add0b748dfbd78ee
SmartCodable: efc682e18fb5eac77f4c0497e37c79590710c192
SmartCodable: 68b3598438181a938eed8ee5623e58ef3e3ea443
SnapKit: d612e99e678a2d3b95bf60b0705ed0a35c03484a
Toast: 1f5ea13423a1e6674c4abdac5be53587ae481c4e
YYKit: 7cda43304a8dc3696c449041e2cb3107b4e236e7
ZFPlayer: 5cf39e8d9f0c2394a014b0db4767b5b5a6bffe13
PODFILE CHECKSUM: d4ff89d9ef2517ec087add019c6f39f8e9ee69d0
PODFILE CHECKSUM: 41b6b69056545708f3956ded0b47fda298f175b8
COCOAPODS: 1.16.2

View File

@ -492,7 +492,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = TWDZ3MP9DV;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Veloria/Source/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
@ -527,7 +527,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = TWDZ3MP9DV;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Veloria/Source/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;

View File

@ -2,7 +2,7 @@
// AppDelegate.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// SceneDelegate.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// VPNavigationController.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,13 +2,48 @@
// VPTabBarController.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit
import ESTabBarController_swift
class VPTabBarController: UITabBarController {
private var ignoreNextSelection = false
override var selectedViewController: UIViewController? {
willSet {
guard let newValue = newValue else {
// if newValue == nil ...
return
}
guard !ignoreNextSelection else {
ignoreNextSelection = false
return
}
guard let tabBar = self.tabBar as? VPTabBar, let index = viewControllers?.firstIndex(of: newValue) else {
return
}
tabBar.select(itemAtIndex: index, animated: false)
}
}
override var selectedIndex: Int {
willSet {
guard let tabBar = self.tabBar as? VPTabBar else {
return
}
guard !ignoreNextSelection else {
ignoreNextSelection = false
return
}
tabBar.select(itemAtIndex: newValue, animated: false)
}
}
override func viewDidLoad() {
super.viewDidLoad()
@ -48,10 +83,10 @@ extension VPTabBarController {
let nav1 = createNavigationController(viewController: VPHomePageViewController(), title: "Home".localized, image: UIImage(named: ""), selectedImage: UIImage(named: ""))
let nav2 = createNavigationController(viewController: VPHomePageViewController(), title: "Home".localized, image: UIImage(named: ""), selectedImage: UIImage(named: ""))
let nav3 = createNavigationController(viewController: VPHomePageViewController(), title: "Home".localized, image: UIImage(named: ""), selectedImage: UIImage(named: ""))
let nav4 = createNavigationController(viewController: VPHomePageViewController(), title: "Home".localized, image: UIImage(named: ""), selectedImage: UIImage(named: ""))
let nav1 = createNavigationController(viewController: VPHomePageViewController(), title: "Home".localized, image: UIImage(named: "tabbar_icon_01"), selectedImage: UIImage(named: "tabbar_icon_01_selected"))
let nav2 = createNavigationController(viewController: VPHomePageViewController(), title: "Home".localized, image: UIImage(named: "tabbar_icon_02"), selectedImage: UIImage(named: "tabbar_icon_02_selected"))
let nav3 = createNavigationController(viewController: VPHomePageViewController(), title: "Home".localized, image: UIImage(named: "tabbar_icon_03"), selectedImage: UIImage(named: "tabbar_icon_03_selected"))
let nav4 = createNavigationController(viewController: VPHomePageViewController(), title: "Home".localized, image: UIImage(named: "tabbar_icon_03"), selectedImage: UIImage(named: "tabbar_icon_04_selected"))
viewControllers = [nav1, nav2, nav3, nav4]
@ -68,6 +103,9 @@ extension VPTabBarController {
// tabBarItem.contentView?.titleLabel.font = .fontRegular(ofSize: 13)
let tabBarItem = VPTabBarItem()
tabBarItem.title = title
tabBarItem.image = image
tabBarItem.selectedImage = selectedImage
let nav = VPNavigationController(rootViewController: viewController)
// nav.tabBarItem.title = title
@ -89,7 +127,7 @@ extension VPTabBarController {
// return;
// }
if let vc = viewControllers?[idx] {
// ignoreNextSelection = true
ignoreNextSelection = true
selectedIndex = idx
delegate?.tabBarController?(self, didSelect: vc)
}

View File

@ -2,7 +2,7 @@
// VPViewController.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// VPDefine.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// UIColor+VPAdd.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// UIDevice+VPAdd.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// UIFont+VPAdd.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// UIScreen+VPAdd.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// UIView+VPAdd.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// VPModel.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// VPCryptorService.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// VPTabBar.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// VPTabBarItem.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit
@ -12,6 +12,23 @@ class VPTabBarItem: UITabBarItem {
private(set) var contentView: VPTabBarItemContentView
override var title: String? {
didSet {
contentView.title = title
}
}
override var image: UIImage? {
didSet {
contentView.image = image
}
}
override var selectedImage: UIImage? {
didSet {
contentView.selectedImage = selectedImage
}
}
public init(_ contentView: VPTabBarItemContentView = VPTabBarItemContentView(), title: String? = nil, image: UIImage? = nil, selectedImage: UIImage? = nil, tag: Int = 0) {
self.contentView = contentView
super.init()

View File

@ -2,7 +2,7 @@
// VPTabBarItemContainer.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit
@ -38,7 +38,7 @@ class VPTabBarItemContainer: UIControl {
super.layoutSubviews()
if let contentView = contentView {
contentView.frame = self.bounds
contentView.updateLayout()
// contentView.updateLayout()
}
}

View File

@ -2,7 +2,7 @@
// VPTabBarItemContentView.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit
@ -19,22 +19,37 @@ class VPTabBarItemContentView: UIView {
///
open var highlightEnabled = true
var title: String? {
didSet {
selectedView.title = title
}
}
var image: UIImage? {
didSet {
normalView.image = image
}
}
var selectedImage: UIImage? {
didSet {
selectedView.image = selectedImage
}
}
private lazy var normalView: VPTabBarItemNormalVew = {
let view = VPTabBarItemNormalVew()
view.isHidden = false
view.alpha = 1
return view
}()
private lazy var selectedView: VPTabBarItemSelectedView = {
let view = VPTabBarItemSelectedView()
view.isHidden = true
view.alpha = 0
return view
}()
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .yellow
self.isUserInteractionEnabled = false
self.layer.masksToBounds = true
@ -66,8 +81,8 @@ class VPTabBarItemContentView: UIView {
}
func updateLayout() {
normalView.isHidden = selected
selectedView.isHidden = !selected
// normalView.isHidden = selected
// selectedView.isHidden = !selected
}
}
@ -138,28 +153,41 @@ extension VPTabBarItemContentView {
// MARK: - ANIMATION METHODS
func selectAnimation(animated: Bool, completion: (() -> ())?) {
self.selectedView.isHidden = false
self.normalView.isHidden = true
// UIView.animate(withDuration: VPTabBar.animateDuration) {
//
//
//
// } completion: { finish in
// <#code#>
// }
if animated {
UIView.animate(withDuration: VPTabBar.animateDuration) { [weak self] in
guard let self = self else { return }
self.selectedView.alpha = 1
self.normalView.alpha = 0
} completion: { finis in
completion?()
}
} else {
self.selectedView.alpha = 1
self.normalView.alpha = 0
completion?()
}
completion?()
}
func deselectAnimation(animated: Bool, completion: (() -> ())?) {
self.selectedView.isHidden = true
self.normalView.isHidden = false
completion?()
if animated {
UIView.animate(withDuration: VPTabBar.animateDuration) { [weak self] in
guard let self = self else { return }
self.selectedView.alpha = 0
self.normalView.alpha = 1
} completion: { finis in
completion?()
}
} else {
self.selectedView.alpha = 0
self.normalView.alpha = 1
completion?()
}
}
func reselectAnimation(animated: Bool, completion: (() -> ())?) {

View File

@ -2,7 +2,7 @@
// VPTabBarItemNormalVew.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,14 +2,26 @@
// VPTabBarItemSelectedView.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit
class VPTabBarItemSelectedView: VPGradientView {
private lazy var contentView: UIView = {
var image: UIImage? {
didSet {
iconImageView.image = image
}
}
var title: String? {
didSet {
titleLabel.text = title
}
}
private lazy var bgView: UIView = {
let view = UIView()
view.backgroundColor = .color353537()
view.layer.cornerRadius = VPTabBar.itemMinWidth / 2 - 3
@ -17,6 +29,23 @@ class VPTabBarItemSelectedView: VPGradientView {
return view
}()
private lazy var contentView: UIView = {
let view = UIView()
return view
}()
private lazy var iconImageView: UIImageView = {
let imageView = UIImageView()
return imageView
}()
private lazy var titleLabel: UILabel = {
let label = UILabel()
label.font = .fontRegular(ofSize: 13)
label.textColor = .colorFFFFFF()
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
colors = [UIColor.color7C174F().cgColor, UIColor.color05CEA0().cgColor]
@ -41,14 +70,33 @@ class VPTabBarItemSelectedView: VPGradientView {
extension VPTabBarItemSelectedView {
private func vp_setupUI() {
addSubview(contentView)
addSubview(bgView)
bgView.addSubview(contentView)
contentView.addSubview(iconImageView)
contentView.addSubview(titleLabel)
contentView.snp.makeConstraints { make in
bgView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(3)
make.top.equalToSuperview().offset(3)
make.center.equalToSuperview()
}
contentView.snp.makeConstraints { make in
make.top.bottom.equalToSuperview()
make.centerX.equalToSuperview()
}
iconImageView.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalToSuperview()
}
titleLabel.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalTo(iconImageView.snp.right).offset(8)
make.right.equalToSuperview()
}
}
}

View File

@ -2,7 +2,7 @@
// VPGradientView.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// VPHomePageViewController.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// VPAppTool.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

@ -2,7 +2,7 @@
// VPLocalizedManager.swift
// Veloria
//
// Created by on 2025/5/19.
// Created by Veloria on 2025/5/19.
//
import UIKit

View File

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

View File

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

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 915 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 691 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 945 B

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 B

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1016 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B

View File

@ -2,7 +2,7 @@
Localizable.strings
VideoPlayer
Created by 佳尔 on 2025/5/19.
Created by Veloria on 2025/5/19.
*/