|
@@ -156,7 +156,7 @@ public class ComponentGroup: NSView, NibLoadable {
|
|
|
}
|
|
|
|
|
|
//MARK: - Show
|
|
|
-
|
|
|
+ //Point是相对于当前WIndow的point,
|
|
|
public func showWithPoint(_ point: CGPoint, relativeTo positioningView: NSView?) {
|
|
|
|
|
|
var screenRect = NSScreen.main!.frame
|
|
@@ -175,37 +175,45 @@ public class ComponentGroup: NSView, NibLoadable {
|
|
|
windowVC.window?.backgroundColor = NSColor.clear
|
|
|
windowVC.showWindow(nil)
|
|
|
|
|
|
+ var rect = self.frame
|
|
|
if let subView = positioningView {
|
|
|
- var rect = self.frame
|
|
|
- if true {
|
|
|
- let subviewRect = subView.bounds // NSView的坐标
|
|
|
- let subviewWindow = subView.window
|
|
|
- let subviewWindowRect = subView.convert(subviewRect, to: nil) // 转换到窗口坐标
|
|
|
- let subviewscreenRect = subviewWindow?.convertToScreen(subviewWindowRect) ?? CGRectZero // 转换到屏幕坐标 ?
|
|
|
-
|
|
|
- rect.origin.x = subviewscreenRect.origin.x - screenRect.origin.x
|
|
|
- rect.origin.y = subviewscreenRect.origin.y - screenRect.origin.y
|
|
|
- rect.origin.y -= rect.size.height
|
|
|
- }
|
|
|
- var viewWidth: CGFloat = CGRectGetWidth(self.frame)
|
|
|
- for item in menuItemArr {
|
|
|
- ComponentLibrary.shared.configMenuItemComponent(properties: item)
|
|
|
- viewWidth = max(viewWidth, item.propertyInfo.viewWidth)
|
|
|
- }
|
|
|
- rect.size.width = viewWidth
|
|
|
- if(rect.origin.y < 0) {
|
|
|
- rect.origin.y = 0
|
|
|
- }
|
|
|
- self.frame = rect
|
|
|
|
|
|
- if let window = windowVC.window {
|
|
|
- window.contentView?.addSubview(self)
|
|
|
- }
|
|
|
+ let subviewRect = subView.bounds // NSView的坐标
|
|
|
+ let subviewWindow = subView.window
|
|
|
+ let subviewWindowRect = subView.convert(subviewRect, to: nil) // 转换到窗口坐标
|
|
|
+ let subviewscreenRect = subviewWindow?.convertToScreen(subviewWindowRect) ?? CGRectZero // 转换到屏幕坐标 ?
|
|
|
|
|
|
- clearMonitor()
|
|
|
+ rect.origin.x = subviewscreenRect.origin.x - screenRect.origin.x
|
|
|
+ rect.origin.y = subviewscreenRect.origin.y - screenRect.origin.y
|
|
|
+ rect.origin.y -= rect.size.height
|
|
|
|
|
|
- addMonitor()
|
|
|
+ } else {
|
|
|
+ var editPoint = point
|
|
|
+ if let keyWindow = NSApplication.shared.keyWindow, let screen = keyWindow.screen {
|
|
|
+ editPoint.x += keyWindow.frame.origin.x
|
|
|
+ editPoint.y += keyWindow.frame.origin.y
|
|
|
+ }
|
|
|
+ rect.origin.x = editPoint.x
|
|
|
+ rect.origin.y = editPoint.y
|
|
|
}
|
|
|
+ var viewWidth: CGFloat = CGRectGetWidth(self.frame)
|
|
|
+ for item in menuItemArr {
|
|
|
+ ComponentLibrary.shared.configMenuItemComponent(properties: item)
|
|
|
+ viewWidth = max(viewWidth, item.propertyInfo.viewWidth)
|
|
|
+ }
|
|
|
+ rect.size.width = viewWidth
|
|
|
+ if(rect.origin.y < 0) {
|
|
|
+ rect.origin.y = 0
|
|
|
+ }
|
|
|
+ self.frame = rect
|
|
|
+
|
|
|
+ if let window = windowVC.window {
|
|
|
+ window.contentView?.addSubview(self)
|
|
|
+ }
|
|
|
+
|
|
|
+ clearMonitor()
|
|
|
+
|
|
|
+ addMonitor()
|
|
|
|
|
|
}
|
|
|
|