1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // WaitingView.swift
- // PDF Reader Pro
- //
- // Created by liujiajie on 2023/11/9.
- //
- import Cocoa
- @objcMembers class WaitingView: NSView{
- var indicator: NSProgressIndicator?
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
- var _indicator = NSProgressIndicator()
- _indicator.isBezeled = false
- _indicator.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
- _indicator.style = .spinning
- _indicator.controlSize = .regular
- _indicator.usesThreadedAnimation = true
- _indicator.sizeToFit()
- self.addSubview(_indicator)
- _indicator.center()
- self.indicator = _indicator
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
- }
-
- func startAnimation() {
- indicator!.startAnimation(nil)
- }
-
- override func draw(_ dirtyRect: NSRect) {
- NSColor(calibratedRed: 1.0, green: 1.0, blue: 1.0, alpha: 0.5).set()
- NSBezierPath(rect: self.bounds).fill()
- }
- override func mouseDown(with theEvent: NSEvent) {
-
- }
- override func mouseUp(with theEvent: NSEvent) {
-
- }
- }
- extension NSView{
- func center(){
- guard let superview = self.superview else { return }
- self.frame = NSMakeRect(
- 0.5 * (superview.frame.size.width - self.frame.size.width),
- 0.5 * (superview.frame.size.height - self.frame.size.height),
- self.frame.size.width,
- self.frame.size.height
- )
- }
- }
|