1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // BaseXibView.swift
- // KMComponentLibrary
- //
- // Created by wanjun on 2024/6/6.
- //
- import Cocoa
- import AppKit
- @objcMembers
- public class BaseXibView: NSView {
- @IBOutlet var contentView: NSView!
-
- // private var area : NSTrackingArea?
-
-
- // MARK: 初始化
- public required init?(coder decoder: NSCoder) {
- super.init(coder: decoder)
- self.initContentView()
-
-
- }
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
- self.initContentView()
-
-
- }
-
- private func initContentView() {
- let isExist = Bundle.main.path(forResource: String(describing:self.classForCoder.self), ofType: "nib")
- if isExist != nil {
- var topLevelArray: NSArray? = nil
- let resource = NSNib(nibNamed: String(describing:self.classForCoder.self), bundle: Bundle(for: self.classForCoder.self))
-
- if resource != nil {
- if (resource!.instantiate(withOwner: self, topLevelObjects: &topLevelArray)) {
- for view in topLevelArray! {
- if view is NSView {
- contentView = view as? NSView
- break
- }
- }
- }
-
- if contentView == nil {
- contentView = NSView()
- }
- addSubview(contentView)
- contentView.translatesAutoresizingMaskIntoConstraints = false
- NSLayoutConstraint.activate([
- contentView.topAnchor.constraint(equalTo: topAnchor),
- contentView.leftAnchor.constraint(equalTo: leftAnchor),
- contentView.rightAnchor.constraint(equalTo: rightAnchor),
- contentView.bottomAnchor.constraint(equalTo: bottomAnchor)])
- contentView.updateConstraintsForSubtreeIfNeeded()
- }
- }
- }
-
- // public override func updateTrackingAreas() {
- // super.updateTrackingAreas()
- //
- // if let _area = area, _area.rect.isEmpty == false {
- // if (_area.rect.equalTo(bounds)) {
- // return
- // }
- // }
- //
- // if (area != nil) {
- // removeTrackingArea(area!)
- // area = nil
- // }
- //
- // area = NSTrackingArea(rect: bounds, options: [.mouseEnteredAndExited, .mouseMoved, .activeAlways], owner: self)
- // self.addTrackingArea(area!)
- // }
- //
- // public override func mouseEntered(with event: NSEvent) {
- // super.mouseEntered(with: event)
- //
- // }
- //
- // public override func mouseMoved(with event: NSEvent) {
- // super.mouseMoved(with: event)
- //
- // }
- //
- // public override func mouseExited(with event: NSEvent) {
- // super.mouseExited(with: event)
- //
- // }
-
- }
|