Browse Source

将SVProgressHUD+Ex 方法扩展放到库包里,使用laoding时候,自动交换方法

100Years 4 weeks ago
parent
commit
1197b0ee15

+ 2 - 2
Example/Podfile.lock

@@ -6,7 +6,7 @@ PODS:
   - SVProgressHUD (2.3.1):
     - SVProgressHUD/Core (= 2.3.1)
   - SVProgressHUD/Core (2.3.1)
-  - TSSmalCoacopods (0.1.0):
+  - TSSmalCoacopods (1.0.0):
     - Alamofire
     - Kingfisher (= 7.10.0)
     - ObjectMapper (~> 4.2)
@@ -34,7 +34,7 @@ SPEC CHECKSUMS:
   ObjectMapper: e6e4d91ff7f2861df7aecc536c92d8363f4c9677
   SnapKit: d612e99e678a2d3b95bf60b0705ed0a35c03484a
   SVProgressHUD: 4837c74bdfe2e51e8821c397825996a8d7de6e22
-  TSSmalCoacopods: 65110736d26232bb325fb84dc6a4a255a898bc97
+  TSSmalCoacopods: 6aa97167f0c76b16fc7d1fd1eb198bb6aece4f68
 
 PODFILE CHECKSUM: 57ffdc1965423d7bf7c0a8940dcfc78203663da7
 

+ 2 - 2
Example/Pods/Local Podspecs/TSSmalCoacopods.podspec.json

@@ -1,6 +1,6 @@
 {
   "name": "TSSmalCoacopods",
-  "version": "0.1.0",
+  "version": "1.0.0",
   "summary": "Lightweight library for doing project basics.",
   "description": "TSSmalCoacopods is a lightweight library that provides essential utilities for iOS development, including network requests, UI components, and third-party integrations like SVProgressHUD, ObjectMapper, SnapKit, Kingfisher, and Alamofire.",
   "homepage": "https://github.com/MG.Max/TSSmalCoacopods",
@@ -13,7 +13,7 @@
   },
   "source": {
     "git": "https://github.com/MG.Max/TSSmalCoacopods.git",
-    "tag": "0.1.0"
+    "tag": "1.0.0"
   },
   "platforms": {
     "ios": "14.0"

+ 2 - 2
Example/Pods/Manifest.lock

@@ -6,7 +6,7 @@ PODS:
   - SVProgressHUD (2.3.1):
     - SVProgressHUD/Core (= 2.3.1)
   - SVProgressHUD/Core (2.3.1)
-  - TSSmalCoacopods (0.1.0):
+  - TSSmalCoacopods (1.0.0):
     - Alamofire
     - Kingfisher (= 7.10.0)
     - ObjectMapper (~> 4.2)
@@ -34,7 +34,7 @@ SPEC CHECKSUMS:
   ObjectMapper: e6e4d91ff7f2861df7aecc536c92d8363f4c9677
   SnapKit: d612e99e678a2d3b95bf60b0705ed0a35c03484a
   SVProgressHUD: 4837c74bdfe2e51e8821c397825996a8d7de6e22
-  TSSmalCoacopods: 65110736d26232bb325fb84dc6a4a255a898bc97
+  TSSmalCoacopods: 6aa97167f0c76b16fc7d1fd1eb198bb6aece4f68
 
 PODFILE CHECKSUM: 57ffdc1965423d7bf7c0a8940dcfc78203663da7
 

File diff suppressed because it is too large
+ 241 - 222
Example/Pods/Pods.xcodeproj/project.pbxproj


+ 1 - 1
Example/Pods/Target Support Files/TSSmalCoacopods/TSSmalCoacopods-Info.plist

@@ -15,7 +15,7 @@
   <key>CFBundlePackageType</key>
   <string>FMWK</string>
   <key>CFBundleShortVersionString</key>
-  <string>0.1.0</string>
+  <string>1.0.0</string>
   <key>CFBundleSignature</key>
   <string>????</string>
   <key>CFBundleVersion</key>

+ 1 - 58
Example/TSSmalCoacopods/AppDelegate.swift

@@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
 
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
         // Override point for customization after application launch.
-        SVProgressHUD.swizzleMethods()
+
         return true
     }
 
@@ -46,60 +46,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
 }
 
 
-
-import Foundation
-import ObjectiveC
-import SVProgressHUD
-extension SVProgressHUD {
-    // 重写 moveToPoint:rotateAngle: 方法
-    @objc dynamic func swizzledMoveToPoint(_ newCenter: CGPoint, rotateAngle angle: CGFloat) {
-        // 调用原方法
-        self.swizzledMoveToPoint(newCenter, rotateAngle: angle)
-        
-        // 使用运行时获取 hudView 属性
-        if let hudView = getHudView() {
-            if let containerView = containerView {
-                hudView.center = CGPoint(x: containerView.bounds.size.width/2 + offsetFromCenter.horizontal, y: containerView.bounds.size.height/2 + offsetFromCenter.vertical)
-            } else {
-                hudView.center = CGPoint(x: newCenter.x + offsetFromCenter.horizontal, y: newCenter.y + offsetFromCenter.vertical)
-            }
-        }
-    }
-    
-    // 获取 hudView 属性
-    private func getHudView() -> UIVisualEffectView? {
-        var count: UInt32 = 0
-        guard let classProperties = class_copyPropertyList(SVProgressHUD.self, &count) else {
-            return nil
-        }
-        
-        for i in 0..<Int(count) {
-            let property = classProperties[i]
-            let propertyName = String(cString: property_getName(property))
-            if propertyName == "hudView" {
-                let hudView = value(forKey: propertyName) as? UIVisualEffectView
-                free(classProperties)
-                return hudView
-            }
-        }
-        
-        free(classProperties)
-        return nil
-    }
-}
-
-// 方法交换
-extension SVProgressHUD {
-    static func swizzleMethods() {
-        // 手动创建选择器
-        let originalSelector = NSSelectorFromString("moveToPoint:rotateAngle:")
-        let swizzledSelector = #selector(SVProgressHUD.swizzledMoveToPoint(_:rotateAngle:))
-        
-        let originalMethod = class_getInstanceMethod(SVProgressHUD.self, originalSelector)
-        let swizzledMethod = class_getInstanceMethod(SVProgressHUD.self, swizzledSelector)
-        
-        if let originalMethod = originalMethod, let swizzledMethod = swizzledMethod {
-            method_exchangeImplementations(originalMethod, swizzledMethod)
-        }
-    }
-}

+ 63 - 0
TSSmalCoacopods/Classes/Tool/SVProgressHUD+Ex.swift

@@ -0,0 +1,63 @@
+//
+//  SVProgressHUD+Ex.swift
+//  TSSmalCoacopods_Example
+//
+//  Created by 100Years on 2025/3/11.
+//  Copyright © 2025 CocoaPods. All rights reserved.
+//
+import Foundation
+import ObjectiveC
+import SVProgressHUD
+extension SVProgressHUD {
+    // 重写 moveToPoint:rotateAngle: 方法
+    @objc dynamic func swizzledMoveToPoint(_ newCenter: CGPoint, rotateAngle angle: CGFloat) {
+        // 调用原方法
+        self.swizzledMoveToPoint(newCenter, rotateAngle: angle)
+        print("swizzledMoveToPoint swizzledMoveToPoint")
+        // 使用运行时获取 hudView 属性
+        if let hudView = getHudView() {
+            if let containerView = containerView {
+                hudView.center = CGPoint(x: containerView.bounds.size.width/2 + offsetFromCenter.horizontal, y: containerView.bounds.size.height/2 + offsetFromCenter.vertical)
+            } else {
+                hudView.center = CGPoint(x: newCenter.x + offsetFromCenter.horizontal, y: newCenter.y + offsetFromCenter.vertical)
+            }
+        }
+    }
+    
+    // 获取 hudView 属性
+    private func getHudView() -> UIVisualEffectView? {
+        var count: UInt32 = 0
+        guard let classProperties = class_copyPropertyList(SVProgressHUD.self, &count) else {
+            return nil
+        }
+        
+        for i in 0..<Int(count) {
+            let property = classProperties[i]
+            let propertyName = String(cString: property_getName(property))
+            if propertyName == "hudView" {
+                let hudView = value(forKey: propertyName) as? UIVisualEffectView
+                free(classProperties)
+                return hudView
+            }
+        }
+        
+        free(classProperties)
+        return nil
+    }
+}
+
+// 方法交换
+extension SVProgressHUD {
+    static func swizzleMethods() {
+        // 手动创建选择器
+        let originalSelector = NSSelectorFromString("moveToPoint:rotateAngle:")
+        let swizzledSelector = #selector(SVProgressHUD.swizzledMoveToPoint(_:rotateAngle:))
+        
+        let originalMethod = class_getInstanceMethod(SVProgressHUD.self, originalSelector)
+        let swizzledMethod = class_getInstanceMethod(SVProgressHUD.self, swizzledSelector)
+        
+        if let originalMethod = originalMethod, let swizzledMethod = swizzledMethod {
+            method_exchangeImplementations(originalMethod, swizzledMethod)
+        }
+    }
+}

+ 1 - 0
TSSmalCoacopods/Classes/Tool/TSToastTool.swift

@@ -14,6 +14,7 @@ open class TSToastTool {
     public static let shared = TSToastTool()
     
     private init() {
+        SVProgressHUD.swizzleMethods()
 //        如果您想要堆叠 HUD,您可以使用以下方法平衡每个节目通话:
 //        [SVProgressHUD popActivity];
         SVProgressHUD.setDefaultStyle(.dark)

Some files were not shown because too many files changed in this diff