我正在使用以下代码添加启动画面,但看到崩溃会在2秒后关闭
@IBOutlet var customView: NSView!
override func viewDidLoad() {
super.viewDidLoad()
let splashScreen : NSImageView
let rect : NSRect = NSMakeRect(0, 0, 421, 231)
let splashWindow : NSWindow = NSWindow.init(contentRect: rect, styleMask: .borderless, backing: .buffered, defer: true)
splashScreen = NSImageView.init(frame: rect)
splashScreen.imageScaling = .NSScaleToFit
splashScreen.image = NSImage.init(named: "splashScreen.jpg")
customView.addSubview(splashScreen)
let xPos :CGFloat = splashWindow.screen!.frame.width / 2 - splashWindow.frame.width / 2
let yPos : CGFloat = splashWindow.screen!.frame.width / 2 - splashWindow.frame.width / 2
splashWindow.setFrame(NSRect(x: xPos, y: yPos, width: splashWindow.frame.width, height: splashWindow.frame.height), display: true)
sleep(2)
splashWindow.close()
崩溃发生在
splashWindow.close()
我也尝试替换
splashWindow.perform(#selector(splashWindow.close), with: nil, afterDelay: 2)
但是不走运,如果您能指出一些教程,以使用swift将启动屏幕添加到可可应用中,这将对您大有帮助