美文网首页
监听屏幕亮度

监听屏幕亮度

作者: Heikki_ | 来源:发表于2017-03-23 17:09 被阅读76次
        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
    

    相关文章

      网友评论

          本文标题:监听屏幕亮度

          本文链接:https://www.haomeiwen.com/subject/fndtottx.html