监听屏幕亮度

2017-03-23  本文已影响76人  Heikki_
    override func viewDidLoad() {
        super.viewDidLoad()
        UIScreen.main.addObserver(self, forKeyPath: "brightness", options: .new, context: nil)
    }

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        print(object ?? "object","---",change ?? "change","---",context ?? "context")   
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        UIScreen.main.brightness  -= 0.1
    }

[__C.NSKeyValueChangeKey(_rawValue: new): 0.4492022693157196,为新的亮度值

<UIScreen: 0x100e013a0; bounds = {{0, 0}, {736, 414}}; mode = <UIScreenMode: 0x170033780; size = 1242.000000 x 2208.000000>> --- [__C.NSKeyValueChangeKey(_rawValue: new): 0.4492022693157196, __C.NSKeyValueChangeKey(_rawValue: kind): 1] --- context
<UIScreen: 0x100e013a0; bounds = {{0, 0}, {736, 414}}; mode = <UIScreenMode: 0x170033780; size = 1242.000000 x 2208.000000>> --- [__C.NSKeyValueChangeKey(_rawValue: new): 0.3492022752761841, __C.NSKeyValueChangeKey(_rawValue: kind): 1] --- context
上一篇下一篇

猜你喜欢

热点阅读