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

本文共 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://jhkul.baihongyu.com/

你可能感兴趣的文章
网上外卖及订餐系统的数据库设计
查看>>
Navicat Premium 数据传输如何设置
查看>>
java G1
查看>>
基于pcDuino的WiFi实时视频监控智能小车——硬件部分(二)
查看>>
01-UI基础-04-02-UITableView : UIScrollView
查看>>
linux md5sum 的用法
查看>>
Java高级-HashMap工作机制
查看>>
Windows 64位系统安装Apache2.4+PHP5.5+MySQL5.6
查看>>
MySQL事务隔离级别介绍及设置
查看>>
jquery grep()筛选遍历数组
查看>>
RN开发总结 关于RN组件的导出export和export default
查看>>
Nginx+keepalived双机热备+负载均衡 ???待续
查看>>
搜素框架
查看>>
使用Xtrabackup对MySQL做主从复制
查看>>
HTML 元素和有效的 DTD文档类型
查看>>
shell 调试技术,伪信号打印程序出错位置
查看>>
(转)批处理
查看>>
struts标签绑定Map<String, List<Map<String, Object>>>
查看>>
navigator.userAgent.indexOf来判断浏览器类型
查看>>
【重磅消息】-支付宝小程序可以申请公测啦!!!
查看>>