覆盖接近传感器时保持显示 [英] Keep display on when the proximity sensor is covered

查看:215
本文介绍了覆盖接近传感器时保持显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不关闭显示屏的情况下拦截接近传感器。

I want to intercept the proximity sensor without turning off the display.

据我所知,我有两个Bool变量:

I know by the documentation that I have two Bool variables:

proximityMonitoringEnabled
proximityState

和此代码

[UIDevice currentDevice].proximityMonitoringEnabled = YES;

当接近传感器检测到某些东西时,它会关闭显示屏,就像你持有时一样通过电话拨打电话。

When the proximity sensor detects something it turns off the display, same way it does when you're holding the phone to your ear when on a phone call.

当接近传感器被遮盖时如何保持显示器开启?

How do I keep the display on when the proximity sensor is covered?

推荐答案

Apple的文档指出并非所有iPhone OS设备都有接近传感器。要确定您的应用程序运行的设备是否支持接近监控,请将proximityMonitoringEnabled属性设置为YES,然后检查它的值:

Apple’s documentation notes that "Not all iPhone OS devices have proximity sensors." To determine if the device your app is running supports proximity monitoring, set the proximityMonitoringEnabled property to YES, then check its value:

UIDevice *device = [UIDevice currentDevice];
[device setProximityMonitoringEnabled:YES];

if (device.proximityMonitoringEnabled == YES) {
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(proximityChanged:) 
                                                 name:@"UIDeviceProximityStateDidChangeNotification"
                                               object:device];
}

- (void) proximityChanged:(NSNotification *)notification {
    UIDevice *device = [notification object];
    NSLog(@"In proximity: %i", device.proximityState);
}

资料来源: http://www.whatsoniphone.com/blog/new-in-iphone-30 -tutorial-series-part-4-proximity-detection /

将有助于检测传感器的当前状态。

Will help to detect current state of sensor.

允许屏幕变暗的公共API:

Public API that allows screen dim:

[UIScreen mainScreen].wantsSoftwareDimming = YES;
[UIScreen mainScreen].brightness = $your_brightness_value;

在此处找到:在iOS 6中更改为wantsSoftwareDimming?

这篇关于覆盖接近传感器时保持显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆