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 <ASCScreenBrightnessDetector/ASCScreenBrightnessDetector.h>

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<ASCScreenBrightnessDetectorDelegate> 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 CocoaPods, 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, @aschndr

License

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

最新文章

  1. ThinkPHP跨控制器调用方法
  2. My family No.1
  3. 【转】webGL与OpenGL的不同
  4. jquery selector 基础
  5. kinect学习笔记(三)&mdash;&mdash;深度数据的提取
  6. Linux下DNS服务器的基本搭建
  7. Ubuntu下使用sshfs挂载远程目录到本地(和Windows挂载盘一样)
  8. 华为C8816电信版ROOT过程
  9. Python学习入门基础教程(learning Python)--3.3.3 Python逻辑关系表达式
  10. Blink: Chromium的新渲染引擎
  11. 登陆模块的进化史,带大家回顾java学习历程(一)
  12. linux 中nvme 的中断申请及处理
  13. 免费申请使用IBM Cloud Lite(轻量套餐) 详细教程指南
  14. 用node.js express设置路径后 子路径下的页面访问静态资源路径出问题
  15. LMerge-github
  16. Python学习笔记【第十五篇】:Python网络编程三ftp案例练习--断点续传
  17. IIS 常见异常及解决办法
  18. Oracle null判断并替换空值
  19. 范型方法 &amp; 范型参数 &amp; 范型返回值
  20. UIProgressView进度条

热门文章

  1. Jmeter创建一个点对点的 JMS 测试计划
  2. Mac 提交代码到Github
  3. Struts2 Validate
  4. VirtualBox虚拟机克隆方法
  5. WPF中设置Border的BorderThickness属性会让背景图片产生模糊感
  6. mysql经典查询
  7. ognl,jstl,struts2标签中符号#,$,%的用法
  8. MVC5 知识点记录
  9. JSONP数据调用
  10. SQL Serever学习10——T-SQL语句