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.

[翻译] ASCScreenBrightnessDetector的更多相关文章

  1. 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...

  2. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  3. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  4. 【探索】机器指令翻译成 JavaScript

    前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...

  5. 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...

  6. 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...

  7. 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...

  8. 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?

    0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...

  9. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点

    在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...

随机推荐

  1. css3基础下

    box-shadow:0 5px 5px rgba(0,0,0,0.5) 文本 text-shadow:5px 5px 4px green; word-wrap: 背景: background:#ff ...

  2. Hardware Emulation Platform (硬件仿真平台) 在IC验证中的运用情况如何?

    三个EDA公司都有自己的hardware emulation verification platform: Cadence Palladium, Synopsys ZeBu, Mentor Veloc ...

  3. Training Logisches Denken

    1.Das Begriff 1.1 Die Arten von Begriff 1.1.1 alleines Begriff,universales Begriff,Leeres Begriff: A ...

  4. CUBA-Platform将全面助力中国开发者

    关注CUBA的伙伴们,你们好! 今天我们有新的进展告诉大家. 九月十五日到十六日CUBA平台事业部负责人(同时也是Haulmont公司合伙人)专程来到中国与CUBA中国团队进行了两天时间的交流.讨论. ...

  5. JAVA练手--线程(Thread)

    1. 查看线程是否还存活 package tet;public class kk extends Thread{ //1. 查看线程是否还存活 public void run(){ for(int i ...

  6. Eclipse常用快捷键之技巧篇

    如何让你阅读代码如虎添翼?使用快捷键可以让你快到飞起来~ 显示类的方法和属性:ctrl+o ctrl+o能够看到你的类的层次结构,使你搜索该类某个方法更加的方便 显示类的继承:ctrl+T ctrl+ ...

  7. 禁止选中页面内容-兼容ie、firefox、chrome

    使用js禁止用户选中网页上的内容,IE及Chrome下的方法一样.使用onselectstart, 比如: 在body中加入<body onselectstart="return fa ...

  8. C# 之构造函数

    构造函数是一种特殊的成员函数,它主要用于为对象分配存储空间,对数据成员进行初始化. 构造函数具有一些特殊的性质: (1)构造函数的名字必须与类同名; (2)构造函数没有返回类型,它可以带参数,也可以不 ...

  9. [javaSE] 数据结构(二叉树-遍历与查找)

    前序遍历:中,左,右 中序遍历:左,中,右 后序遍历:左,右,中 二叉树查找 从根节点进行比较,目标比根节点小,指针移动到左边 从根节点进行比较,目标比根节点大,指针移动到右边 /** * 前序遍历 ...

  10. 关系型数据库之MySQL基础总结_part1

    一:数据库的操作语言的种类 MySQL 是我们最常使用的关系型数据库,对于MySQL的操作的语言种类又可以分为:DDL,DML,DCL,DQL DDL:是数据库的定义语言:主要对于数据库信息的一些定义 ...