如何快速获取分辨率更改事件? [英] How to get resolution change event in swift?

查看:137
本文介绍了如何快速获取分辨率更改事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试制作一个应用程序,现在当屏幕分辨率改变时,我应该进行一些改变,但是我找不到如何截获此事件的方法.

I try to make an app, and now i shoud make some changes when screen resolution will change, but i coudn't find how to intercept this event.

您有什么想法吗?我该如何参加那个活动?

Do you have any ideea how can i take that event?

推荐答案

更改计算机连接的显示器的配置时,会发布NSApplicationDidChangeScreenParametersNotification ,因此 您可以注册该通知,例如与

The NSApplicationDidChangeScreenParametersNotification is posted when the configuration of the displays attached to the computer is changed, so you can register for that notification, e.g. with

NSNotificationCenter.defaultCenter().addObserverForName(NSApplicationDidChangeScreenParametersNotification,
    object: NSApplication.sharedApplication(),
    queue: NSOperationQueue.mainQueue()) {
        notification -> Void in
        println("screen parameters changed")
}

请注意,导致此通知的原因可能有多种 被解雇码头尺寸的变化(如可可码头会触发NSApplicationDidChangeScreenParametersNotification ),因此您必须 记住"旧的分辨率,并将其与新的分辨率进行比较.

Note that there can be various reasons why this notification is fired, e.g. a change in the dock size (as observed in Cocoa Dock fires NSApplicationDidChangeScreenParametersNotification), so you have to "remember" the old resolution and compare it with the new resolution.

这篇关于如何快速获取分辨率更改事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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