覆盖接近传感器时保持显示

编程入门 行业动态 更新时间:2024-10-08 13:35:28
本文介绍了覆盖接近传感器时保持显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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); }

资料来源: www.whatsoniphone/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?

更多推荐

覆盖接近传感器时保持显示

本文发布于:2023-11-24 00:56:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623381.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:传感器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!