Forráskód Böngészése

做了一些改动

100Years 1 hete
szülő
commit
866c976132

+ 4 - 4
TSSmalCoacopods/Classes/BaseClass/TSBaseNavigationBarView.swift

@@ -56,7 +56,7 @@ open class TSNormalNavigationBarView: TSBaseNavContentBarView {
     public lazy var leftNavBtn: UIButton = {
         let button = createNavButton()
         button.contentHorizontalAlignment = .left
-        button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
+        button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
         return button
     }()
 
@@ -72,7 +72,7 @@ open class TSNormalNavigationBarView: TSBaseNavContentBarView {
         button.titleLabel?.adjustsFontSizeToFitWidth = true
         button.contentHorizontalAlignment = .right
         button.setTitleColor(TSColorConfigShared.themeColor, for: .normal)
-        button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10)
+        button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
         return button
     }()
 
@@ -98,8 +98,8 @@ open class TSNormalNavigationBarView: TSBaseNavContentBarView {
     }
 
     private func createView() {
-        let space: CGFloat = 10
-        let margins: CGFloat = 6
+//        let space: CGFloat = 10
+        let margins: CGFloat = 16
 
         backgroundColor = navBgColor
 

+ 9 - 1
TSSmalCoacopods/Classes/Ex/UIButton+Ex.swift

@@ -110,7 +110,15 @@ public extension UIButton {
     }
     
     
-    
+
+    public func preventMultipleTaps(delay: Double = 0.75) {
+        self.isEnabled = false
+        DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
+            self.isEnabled = true
+        }
+    }
+  
+
 
 }
 

+ 7 - 1
TSSmalCoacopods/Classes/Ex/UIImageView+Ex.swift

@@ -35,11 +35,17 @@ public extension UIImageView {
     ///   - contentMode: 内容模式,默认为 `.scaleAspectFit`
     ///   - backgroundColor: 背景颜色,默认为透明
     /// - Returns: 配置完成的 UIImageView 实例
-    static public func createImageView(imageName: String? = nil,
+    static public func createImageView(
+                                image:UIImage? = nil,
+                                imageName: String? = nil,
                                 contentMode: UIView.ContentMode = .scaleAspectFit,
                                 backgroundColor: UIColor = .clear,
                                 corner: CGFloat = 0.0) -> UIImageView {
         let imageView = UIImageView()
+                                    
+        if let image = image{
+            imageView.image = image
+        }
 
         if let imageName = imageName ,imageName.count > 0 {
             imageView.image = UIImage(named: imageName)

+ 1 - 1
TSSmalCoacopods/Classes/Ex/UILabel+Ex.swift

@@ -21,7 +21,7 @@ public extension UILabel {
                             font: UIFont? = nil,
                             textColor: UIColor? = nil,
                             textAlignment: NSTextAlignment = .left,
-                            numberOfLines: Int = 1,
+                            numberOfLines: Int = 0,
                             backgroundColor: UIColor? = nil,
                             adjustsFontSizeToFitWidth: Bool = false,
                             cornerRadius: CGFloat = 0) -> UILabel {

+ 49 - 1
TSSmalCoacopods/Classes/Ex/UIViewController+Ex.swift

@@ -9,6 +9,7 @@ public extension UIViewController {
     func showCustomAlert(
         title: String? = "",
         message: String?,
+        rightActionString:String = "Delete".localized,
         deleteHandler: (() -> Void)? = nil,
         cancelHandler: (() -> Void)? = nil
     ) {
@@ -40,7 +41,7 @@ public extension UIViewController {
         }
         alert.addAction(cancelAction)
         
-        let deleteAction = UIAlertAction(title: "Delete".localized, style: .destructive) { _ in
+        let deleteAction = UIAlertAction(title: rightActionString, style: .destructive) { _ in
             deleteHandler?()
         }
         alert.addAction(deleteAction)
@@ -101,6 +102,53 @@ public extension UIViewController {
         // 显示弹窗
         present(alert, animated: true, completion: nil)
     }
+    
+    
+    func showDeleteErrorAlert(
+        title: String? = "",
+        message: String?,
+        deleteHandler: (() -> Void)? = nil,
+        cancelHandler: (() -> Void)? = nil
+    ) {
+        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
+        
+        // 自定义标题
+        if let title = title {
+            let titleAttributes: [NSAttributedString.Key: Any] = [
+                .font: UIFont.boldSystemFont(ofSize: 20),
+                .foregroundColor: UIColor.white
+            ]
+            let attributedTitle = NSAttributedString(string: title, attributes: titleAttributes)
+            alert.setValue(attributedTitle, forKey: "attributedTitle")
+        }
+        
+        // 自定义消息
+        if let message = message {
+            let messageAttributes: [NSAttributedString.Key: Any] = [
+                .font: UIFont.boldSystemFont(ofSize: 17),
+                .foregroundColor: UIColor.white
+            ]
+            let attributedMessage = NSAttributedString(string: message, attributes: messageAttributes)
+            alert.setValue(attributedMessage, forKey: "attributedMessage")
+        }
+        
+        // 添加按钮
+        let cancelAction = UIAlertAction(title: "Retain".localized, style: .cancel) { _ in
+            cancelHandler?()
+        }
+        alert.addAction(cancelAction)
+        
+        let deleteAction = UIAlertAction(title: "Delete".localized, style: .destructive) { _ in
+            deleteHandler?()
+        }
+        alert.addAction(deleteAction)
+        
+        // 设置黑暗模式
+        alert.overrideUserInterfaceStyle = .dark
+        
+        // 显示弹窗
+        present(alert, animated: true, completion: nil)
+    }
 }
 
 

+ 78 - 0
TSSmalCoacopods/Classes/Tool/TSCollectionViewObserver.swift

@@ -0,0 +1,78 @@
+//
+//  Untitled.swift
+//  Pods
+//
+//  Created by 100Years on 2025/5/16.
+//
+
+
+public class TSCollectionViewObserver {
+    private weak var collectionView: UICollectionView?
+    private var observers: [NSKeyValueObservation] = []
+    
+    public var onContentSizeChange: ((CGSize) -> Void)?
+    public var onContentInsetChange: ((UIEdgeInsets) -> Void)?
+    public var onContentOffsetChange: ((CGPoint) -> Void)?
+    
+    public init(collectionView: UICollectionView) {
+        self.collectionView = collectionView
+        setupObservers()
+    }
+    
+    private func setupObservers() {
+        guard let collectionView = collectionView else { return }
+        
+        observers.append(
+            collectionView.observe(\.contentSize, options: [.new, .old]) { [weak self] (_, change) in
+                guard let newSize = change.newValue, newSize != change.oldValue else { return }
+                self?.onContentSizeChange?(newSize)
+            }
+        )
+        
+        observers.append(
+            collectionView.observe(\.contentInset, options: [.new, .old]) { [weak self] (_, change) in
+                guard let newInset = change.newValue, newInset != change.oldValue else { return }
+                self?.onContentInsetChange?(newInset)
+            }
+        )
+        
+        observers.append(
+            collectionView.observe(\.contentOffset, options: [.new]) { [weak self] (_, change) in
+                guard let newOffset = change.newValue else { return }
+                self?.onContentOffsetChange?(newOffset)
+            }
+        )
+    }
+    
+    deinit {
+        observers.forEach { $0.invalidate() }
+    }
+}
+
+
+
+//        collectionViewObserverHandle()
+//
+//private var collectionViewObserver: CollectionViewObserver!
+//func collectionViewObserverHandle(){
+//    collectionViewObserver = CollectionViewObserver(collectionView: collectionComponent.collectionView)
+//
+//    collectionViewObserver.onContentSizeChange = { size in
+//        print("collectionViewObserver 内容大小变化: \(size)")
+//    }
+//
+//    collectionViewObserver.onContentInsetChange = { inset in
+//        print("collectionViewObserver 内边距变化: \(inset)")
+//    }
+//
+//    collectionViewObserver.onContentOffsetChange = { offset in
+//        print("collectionViewObserver 偏移量变化: \(offset)")
+//    }
+//
+//}
+//
+//
+//func scrollViewDidScroll(_ scrollView: UIScrollView) {
+//    print("contentOffset 变化: \(scrollView.contentOffset)")
+//    // 实时监听偏移量变化
+//}

+ 27 - 0
TSSmalCoacopods/Classes/Tool/TSCommonTool/TSRandomTextTool.swift

@@ -0,0 +1,27 @@
+//
+//  TSRandomTextTool.swift
+//  Pods
+//
+//  Created by 100Years on 2025/5/15.
+//
+
+public class TSRandomTextTool {
+    private var texts: [String]
+    private var lastIndex: Int?
+
+    public init(texts: [String]) {
+        self.texts = texts
+    }
+    
+    public func getRandomText() -> String? {
+        guard !texts.isEmpty else { return nil }
+        
+        var randomIndex: Int
+        repeat {
+            randomIndex = Int.random(in: 0..<texts.count)
+        } while randomIndex == lastIndex
+        
+        lastIndex = randomIndex
+        return texts[randomIndex]
+    }
+}

+ 7 - 0
TSSmalCoacopods/Classes/Tool/WindowHelper.swift

@@ -69,3 +69,10 @@ open class WindowHelper {
         return base
     }
 }
+
+
+public func kGetScaleHeight(originalSize:CGSize,width:CGFloat) -> CGFloat {
+    let originalScale = originalSize.width/originalSize.height
+    let height = width/originalScale
+    return height
+}

+ 4 - 1
TSSmalCoacopods/Classes/View/TSSaveSuccessTool/TSSaveSuccessTool.swift

@@ -35,10 +35,13 @@ open class TSSaveSuccessTool {
                 if let url = URL(string: "photos-redirect://") {
                     if UIApplication.shared.canOpenURL(url) {
                         UIApplication.shared.open(url, options: [:], completionHandler: nil)
-                        playVibration()
                     }
                 }
             }
+            
+            DispatchQueue.main.async{
+                self.saveSuccessBg.removeFromSuperview()
+            }
         }
         viewButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
         return viewButton

+ 16 - 0
TSSmalCoacopods/Classes/View/UIStackView/TSCustomStackView.swift

@@ -146,3 +146,19 @@ open class TSCustomStackView: UIView {
         }
     }
 }
+
+extension UIStackView {
+    public func addSpacing(length:CGFloat) {
+        let view = UIView()
+        self.addArrangedSubview(view)
+        view.snp.makeConstraints { make in
+            if axis == .vertical {
+                make.width.equalToSuperview()
+                make.height.equalTo(length)
+            } else {
+                make.width.equalTo(length)
+                make.height.equalToSuperview()
+            }
+        }
+    }
+}