2013-03-20 66 views
0

你好iPhone屏幕睡眠 - 建于接近传感器

是可以实现以下几点:

一个。用户将iphone屏幕放下。 b。屏幕睡眠(黑色) c。应用程序reamins在前台具有完整功能

我相信其他应用程序可能会实现这与接近传感器?

这会耗尽电池吗?

干杯!

回答

4

你可以这样做:

[UIDevice currentDevice].proximityMonitoringEnabled = YES; 
BOOL shouldDimScreen = [UIDevice currentDevice].proximityState; 

if (shouldDimScreen) { 
    // do whatever you want 
} else { 
    // light the screen back up 
} 

可以使用NSNotificationCenterUIDeviceProximityStateDidChangeNotification注册,如果你想知道每一次的状态变化。

但是,如果用户暂时不触摸它,iOS会自动关闭屏幕。所以只要你没有turn off the idle timer你的电池寿命会很好,你可能不需要实现这一点。

+0

谢谢Aaron!感激的男人! – TurtleKurtze 2013-03-20 21:16:48