保持窗口始终在最前面? [英] Keep window always on top?

查看:160
本文介绍了保持窗口始终在最前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Objective-C for Cocoa Apps中,可以使用这种方式使窗口始终位于顶部吗?

In Objective-C for Cocoa Apps it's possible to use such way to keep window always on top?

如何使用Swift实现相同的目标?

How to achieve the same with Swift?

self.view.window?.level = NSFloatingWindowLevel

导致构建错误Use of unresolved identifier 'NSFloatingWindowLevel'

推荐答案

要更改窗口级别,您不能在viewDidload中执行此操作,因为视图的window属性始终在那里为零,但是可以覆盖viewDidAppear方法或在IBAction方法:

To change the window level you can't do it inside viewDidload because view's window property will always be nil there but it can be done overriding viewDidAppear method or in a IBAction method:

快捷键1

override func viewDidAppear() {
    super.viewDidAppear()
    view.window?.level = Int(CGWindowLevelForKey(kCGFloatingWindowLevelKey))
}

快捷键2

view.window?.level = Int(CGWindowLevelForKey(.FloatingWindowLevelKey))

快捷键3

view.window?.level = Int(CGWindowLevelForKey(.floatingWindow))

快捷键4

最后,他们修复了奇数语法:

Finally they fixed the odd syntax:

view.window?.level = .floating

这篇关于保持窗口始终在最前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆