Music_Player3/Pods/JXSegmentedView/Sources/Indicator/JXSegmentedIndicatorBaseView.swift
2024-06-03 09:48:39 +08:00

109 lines
4.6 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.

//
// JXSegmentedIndicatorBaseView.swift
// JXSegmentedView
//
// Created by jiaxin on 2018/12/26.
// Copyright © 2018 jiaxin. All rights reserved.
//
import UIKit
public enum JXSegmentedIndicatorPosition {
case top
case bottom
case center
}
open class JXSegmentedIndicatorBaseView: UIView, JXSegmentedIndicatorProtocol {
/// JXSegmentedViewAutomaticDimensioncellgetIndicatorWidth
open var indicatorWidth: CGFloat = JXSegmentedViewAutomaticDimension
open var indicatorWidthIncrement: CGFloat = 0 //cell10 point10=indicatorWidth+indicatorWidthIncrement
/// JXSegmentedViewAutomaticDimensioncellgetIndicatorHeight
open var indicatorHeight: CGFloat = JXSegmentedViewAutomaticDimension
/// JXSegmentedViewAutomaticDimension indicatorHeight/2getIndicatorCornerRadius
open var indicatorCornerRadius: CGFloat = JXSegmentedViewAutomaticDimension
///
open var indicatorColor: UIColor = .red
/// topbottomcenter
open var indicatorPosition: JXSegmentedIndicatorPosition = .bottom
/// verticalOffset
open var verticalOffset: CGFloat = 0
///
open var isScrollEnabled: Bool = true
/// indicatorframecellJXSegmentedTitleDataSourcedisTitleMaskEnabled使
/// indicatorindicatorisIndicatorConvertToItemFrameEnabledtrue
/// indicatorisIndicatorConvertToItemFrameEnabledtrueisIndicatorConvertToItemFrameEnabledtrueindicator
open var isIndicatorConvertToItemFrameEnabled: Bool = true
///
open var scrollAnimationDuration: TimeInterval = 0.25
/// itemcellindicatorWidth=JXSegmentedViewAutomaticDimension
open var isIndicatorWidthSameAsItemContent = false
public override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
open func commonInit() {
}
public func getIndicatorCornerRadius(itemFrame: CGRect) -> CGFloat {
if indicatorCornerRadius == JXSegmentedViewAutomaticDimension {
return getIndicatorHeight(itemFrame: itemFrame)/2
}
return indicatorCornerRadius
}
public func getIndicatorWidth(itemFrame: CGRect, itemContentWidth: CGFloat) -> CGFloat {
if indicatorWidth == JXSegmentedViewAutomaticDimension {
if isIndicatorWidthSameAsItemContent {
return itemContentWidth + indicatorWidthIncrement
}else {
return itemFrame.size.width + indicatorWidthIncrement
}
}
return indicatorWidth + indicatorWidthIncrement
}
public func getIndicatorHeight(itemFrame: CGRect) -> CGFloat {
if indicatorHeight == JXSegmentedViewAutomaticDimension {
return itemFrame.size.height
}
return indicatorHeight
}
public func canHandleTransition(model: JXSegmentedIndicatorTransitionParams) -> Bool {
if model.percent == 0 || !isScrollEnabled {
//model.percent0selectItem(model: JXSegmentedIndicatorParamsModel)
//isScrollEnabledfalse
return false
}
return true
}
public func canSelectedWithAnimation(model: JXSegmentedIndicatorSelectedParams) -> Bool {
if isScrollEnabled && (model.selectedType == .click || model.selectedType == .code) {
//
return true
}
return false
}
//MARK: - JXSegmentedIndicatorProtocol
open func refreshIndicatorState(model: JXSegmentedIndicatorSelectedParams) {
}
open func contentScrollViewDidScroll(model: JXSegmentedIndicatorTransitionParams) {
}
open func selectItem(model: JXSegmentedIndicatorSelectedParams) {
}
}