博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[翻译] ASCScreenBrightnessDetector
阅读量:6225 次
发布时间:2019-06-21

本文共 3520 字,大约阅读时间需要 11 分钟。

ASCScreenBrightnessDetector

 

ASCScreenBrightnessDetector lets you easily detect screen brightness changes and provides some useful delegate methods.

For Example it's very easy to switch between a day and night theme optimized for different lighting conditions:

ASCScreenBrightnessDetector能让你非常便利的检测屏幕亮度,并提供实用的代理方法供你使用。

例如,下面的例子中,在白天和黑夜之间切换可以适用不同的主题。

 

 

Usage

This repository contains an example project that uses the methods provided by ASCScreenBrightnessDetector - just build and run to see it in action.

这个例子中已经包含了使用样例-你可以编译然后自己看一下效果。

Please note: The screen brightness detection will only work on a real device, the Xcode Simulators screen brightness is always 0.5.

注意:屏幕亮度检测只会在真实的设备上使用,模拟器上面永远都是0.5.

Wherever you want to use ASCScreenBrightnessDetector, import the header file as follows:

单例想用ASCScreenBrightnessDetector的时候,导入头文件:

#import "ASCScreenBrightnessDetector.h"

or when using CocoaPods:

如果你用的是CocoaPods,就这么导入头文件:

#import 

To detect the current screen brightness or style you can easily use:

为了检测当前屏幕亮度,你可以这样子使用:

ASCScreenBrightnessDetector *brightnessDetector = [ASCScreenBrightnessDetector new];NSLog(@"Screen brightness: %f", brightnessDetector.screenBrightness); ASCScreenBrightnessStyle style = brightnessDetector.screenBrightnessStyle; switch (style) { case ASCScreenBrightnessStyleDark: // Do something, e.g. set a dark theme. break; case ASCScreenBrightnessStyleLight: // Do something else, e.g set a light theme. break; }

To continuously detect screen brightness changes implement ASCScreenBrightnessDetector as an instance variable, set the delegate and use the following delegate methods:

为了实时监测屏幕亮度的变化,你需要初始化ASCScreenBrightnessDetector这个实例变量,然后设置一个代理:

- (void)screenBrightnessDidChange:(CGFloat)brightness{    NSLog(@"The new brightness is: %f", brightness); } - (void)screenBrightnessStyleDidChange:(ASCScreenBrightnessStyle)style { NSLog(@"The new style is: %u", style); }

 

Properties

The object that acts as the delegate.

这是一个代理对象。

id
delegate;

The brightness level of the screen between 0.0 and 1.0, inclusive. (read-only)

亮度的值是只读的,介于0.0与1.0之间(包括0.0与1.0)

CGFloat screenBrightness;

The style indicates if the screen brightness is dark or light and depends on the defined threshold. (read-only)

亮度指示器用以表示屏幕是亮的还是暗的(只读)

ASCScreenBrightnessStyle screenBrightnessStyle;

The threshold determines whether the brightness style is light or dark. It must have a value between 0.0 and 1.0, inclusive. The default value is 0.5.

这个值标示着明与暗之间的分割线,其值介于0.0到1.0之间,默认值是0.5。

CGFloat threshold;

 

Delegate Methods

Tells the delegate when the screens brightness changed and returns a float value between 0.0 and 1.0, inclusive.

你可以从这个代理方法中获取到亮度的变化,介于0.0与1.0之间(包含0.0与1.0)

- (void)screenBrightnessDidChange:(CGFloat)brightness;

Tells the delegate when the screens brightness style changed and returns anASCScreenBrightnessStyle enumeration.

你可以从这个代理方法中获取亮度风格的变化

- (void)screenBrightnessStyleDidChange:(ASCScreenBrightnessStyle)style;

 

Installation

From CocoaPods

ASCScreenBrightnessDetector is available through , to install it simply add the following line to your Podfile:

ASCScreenBrightnessDetector支持CocoaPods,你可以通过以下一句话来安装到Podfile当中:

pod "ASCScreenBrightnessDetector"

Manually

Drag the ASCScreenBrightnessDetector.h and ASCScreenBrightnessDetector.m source files to your project and you are done.

将ASCScreenBrightnessDetector.h与ASCScreenBrightnessDetector.m拖到你的项目当中。

 

Author

André Schneider, 

 

License

ASCScreenBrightnessDetector is available under the MIT license. See the LICENSE file for more info.

 

转载地址:http://iquna.baihongyu.com/

你可能感兴趣的文章
修改linux下的主机名
查看>>
每天一个linux命令(39):grep 命令
查看>>
centos释放无用内存
查看>>
事必躬亲利与弊
查看>>
马哥笔记第十五天系统安装、kickstart、anaconda、dhcp、tftp、pxe
查看>>
linux shell中单引号、双引号和没有引号的区别
查看>>
我的友情链接
查看>>
NAT使用大全
查看>>
cocos中常见的22中动作
查看>>
Spring 访问数据库的三个方法(2)
查看>>
undefined reference to `libiconv_open 无法编译PHP
查看>>
JAVA后台线程
查看>>
当EditText是多行文本时, 光标如何设置在从左上角
查看>>
Redisbook学习笔记(2)内存映射数据结构(1)整数集合
查看>>
详解java垃圾回收机制(转)及finalize方法(转)
查看>>
log4j2 配置文件
查看>>
python 学习笔记
查看>>
java.io.File.deleteOnExit()-生成临时文件,删除临时文件
查看>>
使用pandas模块帮助朋友处理mysql中的重复数据
查看>>
聊聊并发(七)——Java中的阻塞队列
查看>>