12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- //
- // KMNQuickToolCollectionViewItem.swift
- // PDF Reader Pro
- //
- // Created by 丁林圭 on 2024/10/11.
- //
- import Cocoa
- import KMComponentLibrary
- class KMNQuickToolCollectionViewItem: NSCollectionViewItem, ComponentCardPDFToolDelegate {
-
- @IBOutlet var itemCardView: ComponentCardPDFTool!
-
- @IBOutlet var tagView: ComponentTag!
-
- var clickCallBack: ((Bool) -> Void)?
-
- public var isShowState: Bool = false {
- didSet {
- itemCardView.properties.isSelected = isShowState
- itemCardView.reloadData()
- }
- }
-
- public var isNewState: Bool = false {
- didSet {
- tagView.isHidden = !isNewState
- }
- }
-
- public var quickToolModel:KMNHomeQuickToolMode = KMNHomeQuickToolMode.toolModeData(type:.Batch) {
- didSet {
- let pdftoolProperty: ComponentCardPDFToolProperty = ComponentCardPDFToolProperty(collapse: true,
- state: .normal,
- icon: NSImage(named: quickToolModel.toolImageName),
- text: quickToolModel.toolTitle,
- subText: "",
- selectedAble: true,
- isSelected:false,
- identifyID: "",
- enableMouseEnterExit: false)
- itemCardView.properties = pdftoolProperty
- }
- }
- override func viewDidLoad() {
- super.viewDidLoad()
-
- self.view.wantsLayer = true
-
- itemCardView.delegate = self
-
- tagView.properties = ComponentTagProperty(tagType: .mark_New, size: .m, text: KMLocalizedString("new"))
- tagView.isHidden = true
-
- DispatchQueue.main.async {
- self.itemCardView.reloadData()
- }
- }
-
- //MARK: - ComponentCardPDFToolDelegate
- @objc func componentCardPDFToolDidClicked(_ view: ComponentCardPDFTool) {
- itemCardView.properties.isSelected = !itemCardView.properties.isSelected
- itemCardView.reloadData()
- clickCallBack?(itemCardView.properties.isSelected)
- }
- @objc func componentCardPDFToolDidSelectedStateUpdated(_ view: ComponentCardPDFTool) {
- clickCallBack?(itemCardView.properties.isSelected)
- }
-
- }
- extension NSView {
- func shakeAnimation() {
- let shake = CAKeyframeAnimation(keyPath: "position")
- shake.values = [
- NSValue(point: CGPoint(x: self.bounds.origin.x - 5, y: self.bounds.origin.y)),
- NSValue(point: CGPoint(x: self.bounds.origin.x + 5, y: self.bounds.origin.y)),
- NSValue(point: CGPoint(x: self.bounds.origin.x - 5, y: self.bounds.origin.y)),
- NSValue(point: CGPoint(x: self.bounds.origin.x + 5, y: self.bounds.origin.y)),
- NSValue(point: CGPoint(x: self.bounds.origin.x, y: self.bounds.origin.y))
- ]
- shake.keyTimes = [0, 0.25, 0.5, 0.75, 1]
- shake.duration = 0.5
- shake.isAdditive = true
- shake.timingFunctions = [CAMediaTimingFunction(name: .easeInEaseOut)]
-
- self.layer?.add(shake, forKey: "shake")
- }
- }
|