KMPurchaseAlertView.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // KMPurchaseAlertView.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/7/17.
  6. //
  7. import Cocoa
  8. class KMPurchaseAlertView: KMBaseXibView {
  9. @IBOutlet weak var iconImageView: NSImageView!
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var heightConstraint: NSLayoutConstraint!
  12. @IBOutlet weak var contentBackgroundView: NSView!
  13. var event: Any? = nil
  14. deinit {
  15. self.removeNotification()
  16. KMPrint("KMPurchaseAlertView delloc")
  17. }
  18. override func draw(_ dirtyRect: NSRect) {
  19. super.draw(dirtyRect)
  20. // Drawing code here.
  21. }
  22. static func show(view: NSView, string: String) -> KMPurchaseAlertView? {
  23. // if let window = NSApp.mainWindow {
  24. let alertView = KMPurchaseAlertView(frame: view.bounds )
  25. view.addSubview(alertView)
  26. alertView.titleLabel.stringValue = string
  27. alertView.dismissShow()
  28. return alertView
  29. // }
  30. return nil
  31. }
  32. func dismissShow() {
  33. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3.0) {
  34. NSAnimationContext.runAnimationGroup { NSAnimationContext in
  35. self.animator().alphaValue = 0
  36. self.removeFromSuperview()
  37. }
  38. }
  39. }
  40. override func setup() {
  41. self.contentBackgroundView.backgroundColor(NSColor.km_init(hex: "#000000").withAlphaComponent(1))
  42. self.contentBackgroundView.border(NSColor.clear, 0, 4)
  43. self.titleLabel.textColor = NSColor.km_init(hex: "#FFFFFF")
  44. self.titleLabel.font = NSFont.SFProTextRegularFont(14)
  45. }
  46. override func addNotification() {
  47. // event = NSEvent.addLocalMonitorForEvents(matching: .any) { NSEvent in
  48. // return nil
  49. // }
  50. }
  51. override func removeNotification() {
  52. // if self.event != nil {
  53. // NSEvent.removeMonitor(self.event as Any)
  54. // self.event = nil
  55. // }
  56. }
  57. }
  58. //MARK: 时间拦截
  59. extension KMPurchaseAlertView {
  60. override func mouseUp(with event: NSEvent) {
  61. }
  62. override func mouseDown(with event: NSEvent) {
  63. }
  64. override func mouseMoved(with event: NSEvent) {
  65. }
  66. override func mouseEntered(with event: NSEvent) {
  67. }
  68. override func mouseExited(with event: NSEvent) {
  69. }
  70. }