Con*_*sed 10 monitoring screen ios proximitysensor
经过一些谷歌搜索,我可以理解"接近传感器",当设备离开/靠近用户时,用于开/关屏幕.我观看了这段视频(从第30秒开始观看)并对这些很酷的东西感到惊讶.我想在我的应用程序中实现它.
然而,我想知道有没有公共API可用时,可以保护屏幕锁proximityMonitoringEnabled是YES.然后上面的应用程序如何做到这一点?
为了清楚地理解,我正在复制一些代码.
启用接近传感器:
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
Run Code Online (Sandbox Code Playgroud)
设置传感器更换的观察者:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sensorStateMonitor:) name:@"UIDeviceProximityStateDidChangeNotification" object:nil];
Run Code Online (Sandbox Code Playgroud)
最后,您可以通过以下方法找到接近传感器的状态:
- (void)sensorStateMonitor:(NSNotificationCenter *)notification
{
if ([[UIDevice currentDevice] proximityState] == YES)
{
NSLog(@"Device is close to user.");
}
else
{
NSLog(@"Device is not closer to user.");
}
}
Run Code Online (Sandbox Code Playgroud)
题:
我想在调用"设备接近用户"状态时显示一些视图.并且如果调用"设备不接近用户"状态,则要删除视图.
所以我在sensorStateMonitor:方法中添加了一个视图并删除了.但是视图只在几秒钟内可见,并且屏幕熄灭.
我可以阻止屏幕自动关闭吗?
只是困惑!!
可以启用/禁用屏幕锁定。
[UIApplication sharedApplication].idleTimerDisabled = YES;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6777 次 |
| 最近记录: |