181 lines
5.1 KiB
Swift
181 lines
5.1 KiB
Swift
//
|
|
// VPTabBarItemContentView.swift
|
|
// Veloria
|
|
//
|
|
// Created by 佳尔 on 2025/5/19.
|
|
//
|
|
|
|
import UIKit
|
|
import ESTabBarController_swift
|
|
|
|
class VPTabBarItemContentView: UIView {
|
|
|
|
/// 是否被选中
|
|
open var selected = false
|
|
|
|
/// 是否处于高亮状态
|
|
open var highlighted = false
|
|
|
|
/// 是否支持高亮
|
|
open var highlightEnabled = true
|
|
|
|
|
|
private lazy var normalView: VPTabBarItemNormalVew = {
|
|
let view = VPTabBarItemNormalVew()
|
|
view.isHidden = false
|
|
return view
|
|
}()
|
|
|
|
private lazy var selectedView: VPTabBarItemSelectedView = {
|
|
let view = VPTabBarItemSelectedView()
|
|
view.isHidden = true
|
|
return view
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
backgroundColor = .yellow
|
|
self.isUserInteractionEnabled = false
|
|
self.layer.masksToBounds = true
|
|
|
|
addSubview(normalView)
|
|
addSubview(selectedView)
|
|
|
|
normalView.snp.makeConstraints { make in
|
|
make.center.equalToSuperview()
|
|
make.width.height.equalTo(VPTabBar.itemMinWidth)
|
|
}
|
|
|
|
selectedView.snp.makeConstraints { make in
|
|
make.center.equalToSuperview()
|
|
make.width.equalTo(VPTabBar.itemMaxWidth)
|
|
make.height.equalTo(VPTabBar.itemMinWidth)
|
|
}
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
open func updateDisplay() {
|
|
|
|
// imageView.image = (selected ? (selectedImage ?? image) : image)?.withRenderingMode(renderingMode)
|
|
// imageView.tintColor = selected ? highlightIconColor : iconColor
|
|
// titleLabel.textColor = selected ? highlightTextColor : textColor
|
|
// backgroundColor = selected ? highlightBackdropColor : backdropColor
|
|
}
|
|
|
|
func updateLayout() {
|
|
normalView.isHidden = selected
|
|
selectedView.isHidden = !selected
|
|
|
|
}
|
|
}
|
|
|
|
extension VPTabBarItemContentView {
|
|
|
|
// MARK: - INTERNAL METHODS
|
|
internal final func select(animated: Bool, completion: (() -> ())?) {
|
|
selected = true
|
|
if highlightEnabled && highlighted {
|
|
highlighted = false
|
|
dehighlightAnimation(animated: animated, completion: { [weak self] in
|
|
self?.updateDisplay()
|
|
self?.selectAnimation(animated: animated, completion: completion)
|
|
})
|
|
} else {
|
|
updateDisplay()
|
|
selectAnimation(animated: animated, completion: completion)
|
|
}
|
|
}
|
|
|
|
internal final func deselect(animated: Bool, completion: (() -> ())?) {
|
|
selected = false
|
|
updateDisplay()
|
|
self.deselectAnimation(animated: animated, completion: completion)
|
|
}
|
|
|
|
internal final func reselect(animated: Bool, completion: (() -> ())?) {
|
|
if selected == false {
|
|
select(animated: animated, completion: completion)
|
|
} else {
|
|
if highlightEnabled && highlighted {
|
|
highlighted = false
|
|
dehighlightAnimation(animated: animated, completion: { [weak self] in
|
|
self?.reselectAnimation(animated: animated, completion: completion)
|
|
})
|
|
} else {
|
|
reselectAnimation(animated: animated, completion: completion)
|
|
}
|
|
}
|
|
}
|
|
|
|
internal final func highlight(animated: Bool, completion: (() -> ())?) {
|
|
if !highlightEnabled {
|
|
return
|
|
}
|
|
if highlighted == true {
|
|
return
|
|
}
|
|
highlighted = true
|
|
self.highlightAnimation(animated: animated, completion: completion)
|
|
}
|
|
|
|
internal final func dehighlight(animated: Bool, completion: (() -> ())?) {
|
|
if !highlightEnabled {
|
|
return
|
|
}
|
|
if !highlighted {
|
|
return
|
|
}
|
|
highlighted = false
|
|
self.dehighlightAnimation(animated: animated, completion: completion)
|
|
}
|
|
|
|
internal func badgeChanged(animated: Bool, completion: (() -> ())?) {
|
|
self.badgeChangedAnimation(animated: animated, completion: completion)
|
|
}
|
|
|
|
// 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#>
|
|
// }
|
|
|
|
|
|
|
|
|
|
completion?()
|
|
}
|
|
|
|
func deselectAnimation(animated: Bool, completion: (() -> ())?) {
|
|
self.selectedView.isHidden = true
|
|
self.normalView.isHidden = false
|
|
completion?()
|
|
}
|
|
|
|
func reselectAnimation(animated: Bool, completion: (() -> ())?) {
|
|
completion?()
|
|
}
|
|
|
|
func highlightAnimation(animated: Bool, completion: (() -> ())?) {
|
|
completion?()
|
|
}
|
|
|
|
func dehighlightAnimation(animated: Bool, completion: (() -> ())?) {
|
|
completion?()
|
|
}
|
|
|
|
func badgeChangedAnimation(animated: Bool, completion: (() -> ())?) {
|
|
completion?()
|
|
}
|
|
}
|