Browse Source

【主页】最近列表悬浮效果错乱修复

lizhe 1 year ago
parent
commit
684d57d7e2

+ 39 - 15
PDF Office/PDF Master/Class/Home/ViewController/KMHistoryFileCollectionViewItem.swift

@@ -19,6 +19,11 @@ class KMHistoryFileCollectionViewItem: NSCollectionViewItem {
     var filePathUrl: URL? = nil
     var selectUrls: [URL] = []
     var isSelect: Bool = false
+    var isHover: Bool = false {
+        didSet {
+            self.updateCellState()
+        }
+    }
     var currentWindowController: NSWindowController?
 
     // MARK: init
@@ -30,21 +35,21 @@ class KMHistoryFileCollectionViewItem: NSCollectionViewItem {
         initializeUI()
         mainBox.menu = tableCellMenu
         documentName.maximumNumberOfLines = 2
-        mainBox.moveCallback =  { [unowned self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
-            if !self.isSelect {
-                if mouseEntered {
-                    self.mainBox.fillColor = NSColor(hex: "#EDEEF0")
-                    self.mainBox.borderWidth = 0.0
-                    self.documentName.textColor = NSColor(hex: "#252629")
-                    self.mainBox.cornerRadius = 8.0
-                } else {
-                    self.mainBox.fillColor = .clear
-                    self.mainBox.borderWidth = 0.0
-                    self.documentName.textColor = NSColor(hex: "#252629")
-                    self.mainBox.cornerRadius = 0.0
-                }
-            }
-        }
+//        mainBox.moveCallback =  { [unowned self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
+//            if !self.isSelect {
+//                if mouseEntered {
+//                    self.mainBox.fillColor = NSColor(hex: "#EDEEF0")
+//                    self.mainBox.borderWidth = 0.0
+//                    self.documentName.textColor = NSColor(hex: "#252629")
+//                    self.mainBox.cornerRadius = 8.0
+//                } else {
+//                    self.mainBox.fillColor = .clear
+//                    self.mainBox.borderWidth = 0.0
+//                    self.documentName.textColor = NSColor(hex: "#252629")
+//                    self.mainBox.cornerRadius = 0.0
+//                }
+//            }
+//        }
     }
     
     func initializeUI() {
@@ -79,6 +84,25 @@ class KMHistoryFileCollectionViewItem: NSCollectionViewItem {
         fileImageView.image = image
     }
     
+    //MARK: update
+    func updateCellState() {
+        if fileImageView != nil {
+            if !self.isSelect {
+                if self.isHover {
+                    self.mainBox.fillColor = NSColor(hex: "#EDEEF0")
+                    self.mainBox.borderWidth = 0.0
+                    self.documentName.textColor = NSColor(hex: "#252629")
+                    self.mainBox.cornerRadius = 8.0
+                } else {
+                    self.mainBox.fillColor = .clear
+                    self.mainBox.borderWidth = 0.0
+                    self.documentName.textColor = NSColor(hex: "#252629")
+                    self.mainBox.cornerRadius = 0.0
+                }
+            }
+        }
+    }
+    
     // MARK: Menu
     
     lazy var tableCellMenu: NSMenu = {

+ 15 - 0
PDF Office/PDF Master/Class/Home/ViewController/KMHomeHistoryFileViewController.swift

@@ -294,6 +294,7 @@ class KMHomeHistoryFileViewController: NSViewController, NSCollectionViewDelegat
     
     //hover
     var hoverRow: Int = 0
+    var collectionHoverRow: Int = 0
     // MARK: Init
     
     override func viewWillAppear() {
@@ -689,6 +690,20 @@ class KMHomeHistoryFileViewController: NSViewController, NSCollectionViewDelegat
                     }
                 }
             }
+            
+            item.mainBox.moveCallback = { [unowned self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
+                if self.collectionHoverRow != indexPath.item {
+                    self.historyFileCollectionView.reloadItems(at: [indexPath])
+                }
+                
+                self.collectionHoverRow = indexPath.item
+                item.isHover = mouseEntered
+            }
+            
+            if indexPath.item != self.collectionHoverRow {
+                let cell: KMHistoryFileCollectionViewItem = self.historyFileCollectionView.item(at: self.collectionHoverRow) as! KMHistoryFileCollectionViewItem
+                cell.isHover = false
+            }
             return item
         }
         return NSCollectionViewItem.init()