iOS 调节屏幕明暗度
2015-11-16 23:35
567 查看
1 #import "AppDelegate.h"
2
3 @interface AppDelegate ()
4
5 @end
6
7 @implementation AppDelegate
8
9
10 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
11 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
12 // Override point for customization after application launch.
13 self.window.backgroundColor = [UIColor whiteColor];
14
15 UIDevice *device = [UIDevice currentDevice];
16 device.proximityMonitoringEnabled = YES;
17 if (device.proximityMonitoringEnabled == YES) {
18 [[NSNotificationCenter defaultCenter] addObserver:self
19 selector:@selector(proximityChanged:)
20 name:@"UIDeviceProximityStateDidChangeNotification" object:device];
21 }
22
23 [self.window makeKeyAndVisible];
24 return YES;
25 }
26
27 - (void)tuneBrightness:(NSTimer *)timer
28 {
29 if ([UIScreen mainScreen].brightness < 1) {
30 [UIScreen mainScreen].brightness += 0.05;
31 }else{
32 [timer invalidate];
33 }
34 }
35
36 - (void)proximityChanged:(NSNotification *)notification
37 {
38 UIDevice *device = [notification object];
39 if (!device.proximityState) {
40 [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(tuneBrightness:) userInfo:nil repeats:YES];
41 }
42 }
43
44
45 - (void)applicationWillTerminate:(UIApplication *)application {
46 // 删除Observer
47 [[NSNotificationCenter defaultCenter] removeObserver:self];
48
49 }
50
51 @end
2
3 @interface AppDelegate ()
4
5 @end
6
7 @implementation AppDelegate
8
9
10 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
11 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
12 // Override point for customization after application launch.
13 self.window.backgroundColor = [UIColor whiteColor];
14
15 UIDevice *device = [UIDevice currentDevice];
16 device.proximityMonitoringEnabled = YES;
17 if (device.proximityMonitoringEnabled == YES) {
18 [[NSNotificationCenter defaultCenter] addObserver:self
19 selector:@selector(proximityChanged:)
20 name:@"UIDeviceProximityStateDidChangeNotification" object:device];
21 }
22
23 [self.window makeKeyAndVisible];
24 return YES;
25 }
26
27 - (void)tuneBrightness:(NSTimer *)timer
28 {
29 if ([UIScreen mainScreen].brightness < 1) {
30 [UIScreen mainScreen].brightness += 0.05;
31 }else{
32 [timer invalidate];
33 }
34 }
35
36 - (void)proximityChanged:(NSNotification *)notification
37 {
38 UIDevice *device = [notification object];
39 if (!device.proximityState) {
40 [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(tuneBrightness:) userInfo:nil repeats:YES];
41 }
42 }
43
44
45 - (void)applicationWillTerminate:(UIApplication *)application {
46 // 删除Observer
47 [[NSNotificationCenter defaultCenter] removeObserver:self];
48
49 }
50
51 @end
相关文章推荐
- iOS---APNS(自带)
- iOS开发之Tom猫
- iOS学习:调用相机,选择图片上传,带预览功能
- iOS - Umeng分享
- iOS 多图上传
- iOS - 消息推送
- iOS开发之图片查看器
- iOS - 数据持久化---- NSUserDefaults & NSKeyedArchiver
- iOS小技巧-第三方sdk官网汇总(逐步积累)
- iOS - 常用正则表达式
- iOS - NSDateFormatter 日期 和 字符串
- iOS深入学习Block
- iOS - __weak&&__block
- iOS 拨打电话的方法总结
- ios自动布局(1)
- iOS经典讲解之实现扫描二维码ZBarSDK的使用
- iOS平台基于KVC的JSON与数据对象绑定
- iOS--NSURLSession
- iOS开发:使用Block在两个界面之间传值
- iOS实现一个颜色渐变的弧形进度条