// // KMNCustomAlertView.swift // PDF Reader Pro // // Created by 丁林圭 on 2024/10/14. // import Cocoa import KMComponentLibrary class KMNCustomAlertView: NSView { override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) } static func alertView(message: String, type: ComponentMessageType, fromView supverView: NSView, point: NSPoint) -> ComponentMessage? { let properties: ComponentMessageProperty = ComponentMessageProperty(messageType: type, title: message) let componentMessage = ComponentMessage() componentMessage.properties = properties let offsetSize = NSSize(width: componentMessage.properties.propertyInfo.viewWidth, height: componentMessage.properties.propertyInfo.viewHeight) componentMessage.frame = NSRect(x: (point.x - offsetSize.width/2), y: (point.y - offsetSize.height/2), width: offsetSize.width, height: offsetSize.height) componentMessage.reloadData() supverView.addSubview(componentMessage) componentMessage.alphaValue = 0.0 NSAnimationContext.runAnimationGroup({ context in context.duration = 0.3 // 设置动画持续时间 context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut) componentMessage.animator().alphaValue = 1.0 // 动画化透明度 }, completionHandler: { }) DispatchQueue.main.asyncAfter(deadline: .now() + 2) { NSAnimationContext.runAnimationGroup({ context in context.duration = 0.3 // 设置动画持续时间 context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut) componentMessage.animator().alphaValue = 0.0 // 动画化透明度 }, completionHandler: { componentMessage.removeFromSuperview() }) } return componentMessage } }