所有窗口顶部的应用程序窗口,包括其他应用程序窗口

时间:2018-02-07 09:27:20

标签: swift macos operating-system nswindow

我喜欢让我的NSWindow包括其他应用程序窗口在内的所有内容。这怎么可能?

这是我定制的NSWindow的样子吗?

override init(contentRect: NSRect, styleMask style: NSWindow.StyleMask,
              backing backingStoreType: NSWindow.BackingStoreType, defer flag: Bool) {

    super.init(contentRect: contentRect, styleMask: NSWindow.StyleMask.borderless,
               backing: NSWindow.BackingStoreType.buffered, defer: false)

    // Manage window appearance and size
    // this window manages video view controller
    self.backgroundColor = NSColor.clear
    self.alphaValue = CGFloat(AppSingleton.shared.getVideoOpacity()) / 100
    self.isOpaque = false

    self.collectionBehavior = .transient
    }

这就是我如何通过按钮动作打开NSWindowController

func openPlayerWindow(url: URL) {
    let storyboard:NSStoryboard? = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: Bundle.main)
    let playerWindowController = storyboard?.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "SIPlayerWindowController")) as! PlayerWindowController

    if let playerWindow = playerWindowController.window {
        playerWindowController.showWindow(nil)
        playerWindow.makeKeyAndOrderFront(self)
        NSApp.activate(ignoringOtherApps: true)

        let videoPlayerController = playerWindow.contentViewController as! VideoPlayerViewController
        videoPlayerController.videoFile = url
    }
}

PlayerView.swift

import Cocoa
import AVFoundation

class PlayerView: NSView {

    override func hitTest(_ point: NSPoint) -> NSView? {
        return nil;
    }
}

此PlayerView立即在此函数中填充CorePlayer。 VideoViewController.swift

func playVideo(videoFile: URL) {
        corePlayer.view().translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(corePlayer.view())

        NSLayoutConstraint.init(item: corePlayer.view(), attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 0).isActive = true
        NSLayoutConstraint.init(item: corePlayer.view(), attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: 0).isActive = true
        NSLayoutConstraint.init(item: corePlayer.view(), attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1, constant: 0).isActive = true
        NSLayoutConstraint.init(item: corePlayer.view(), attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0).isActive = true

        corePlayer.playURL(videoFile.absoluteURL)
}

2 个答案:

答案 0 :(得分:2)

尝试使用此

var counter = 0;
var finalArray = []

function test(arr, node) {
  arr.push(node.text);
  if (node.hasOwnProperty("nodes") && Array.isArray(node.nodes) && node.nodes.length != 0) {

    node.nodes.forEach(function(nodeChild) {
      test(arr, nodeChild);

    })

  } else {
    finalArray[counter] = arr.slice();
    counter++;


  }
  arr = arr.slice(0, -1);

}
var b =[ { "text" : "parent1", "nodes" :[ { "text": "child1", "nodes": [ { "text": "grandchild1", "nodes":[ { "text": "hello", "nodes": [] } ] }, { "text": "hello", "nodes":[] } ] } ] }, { "text" : "parent2", "nodes" :[ { "text": "child2", "nodes": [ { "text": "grandchild2", "nodes": [ { "text": "grandgrandchild1", "nodes": [ { "text": "hello", "nodes": [] } ] } ] } ] } ] } ]  
b.forEach(function(nodeVal) {
  test([], nodeVal)

})
console.log(finalArray);

答案 1 :(得分:0)

我找到了解决方案 self.ignoresMouseEvents = true;