iPhone 接近传感器
iPhone SDK 可以利用 iPhone 的接近传感器吗? 如果是这样,为什么没有人利用它们? 我可以想象一些不错的用途。
例如,在赛车游戏中,您可以将手指放在接近传感器上,而不是用拇指占据屏幕空间。 当然,如果这是您唯一的选择,那么 iPod touch 用户将无法使用该应用程序。
接近传感器是否能告诉您距离有多近,或者只是知道它前面有什么东西?
Can the iPhone SDK take advantage of the iPhone's proximity sensors? If so, why hasn't anyone taken advantage of them? I could picture a few decent uses.
For example, in a racing game, you could put your finger on the proximity sensor to go instead of taking up screen real-estate with your thumb. Of course though, if this was your only option, then iPod touch users wouldn't be able to use the application.
Does the proximity sensor tell how close you are, or just that something is in front of it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
有一个公共 API 可以实现此目的。 -[UIApplication setProximitySensingEnabled:(BOOL)] 将打开该功能。 顺便说一句,它似乎没有使用光传感器,因为接近感应会在黑暗的房间里调整。
然而,当您将手机放在脸上时,API 调用基本上会使屏幕空白。 可悲的是,对于交互没有用。
There is a public API for this. -[UIApplication setProximitySensingEnabled:(BOOL)] will turn the feature on. BTW, it doesn't seem to be using the light sensor, because proximity sensing would tweak out in a dark room.
However, the API call basically blanks the screen when you hold the phone up to your face. Not useful for interaction, sadly.
假设您指的是当您将屏幕放在耳边时关闭屏幕的传感器,我很确定这只是耳机内的红外传感器。 如果您启动手机应用程序(不必拨打电话)并按住某物在耳机上投射阴影,则可以关闭显示屏。
当您提出这个问题时,无法通过公共 API 访问它。 您现在可以通过 UIDevice 的 proximityState 属性访问传感器的状态。 然而,它对于游戏来说没有那么有用,因为它只是一个开/关的东西,而不是一个近/远的测量。 另外,它仅适用于 iPhone,不适用于 iPod touch。
Assuming you mean the sensor that shuts off the screen when you hold it to your ear, I'm pretty sure that is just an infrared sensor inside the ear speaker. If you start the phone app (you don't have to be making a call) and hold something to cast a shadow over the ear speaker, you can make the display shut off.
When you asked this question it was not accessible via the public API. You can now access the sensor's state via UIDevice's
proximityState
property. However, it wouldn't be that useful for games, since it is only an on/off thing, not a near/far measure. Plus, it's only available on the iPhone and not the iPod touch.显然,如果状态栏处于横向方向,接近传感器将永远不会打开。
即,如果您拨打:
您将不再收到proximity:ON通知。
这肯定会发生在 OS 3.0 上,我无法在 2.X 设备上测试它,因为我没有带有接近传感器的设备。
这似乎是一个错误。
Evidently the proximity sensor will never turn on if the status bar is in landscape orientation.
i.e, if you call:
You will no longer get the proximity:ON notifications.
This definitely happens on OS 3.0, I can't test it on a 2.X device since I don't have one with a proximity sensor.
This seems like a bug.
接近传感器通过测量红外反射率来工作。 如果将 iPhone 靠近网络摄像头,您可以看到一个小型脉冲红外 LED。
The proximity sensor works via measuring IR reflectance. If you hold the iPhone up to a webcam, you can see a small, pulsing IR LED.
接近传感器和环境光传感器之间存在很多混淆。 iPhone 两者兼而有之。 Touch 没有接近传感器,这使其成为用户输入的糟糕选择。 无论如何,这都是一个坏主意,因为苹果没有义务在未来的设备中将其放置在同一位置; 你不应该知道或关心它在哪里。
接近传感器的工作原理是向红外 LED 发出脉冲并测量反射量。 您可以使用 iSight 摄像头看到这一点(大多数数码相机对红外线敏感)。只需启动 Photo Booth,在手机上发起呼叫(或播放语音邮件)并将其指向您的 iSight 摄像头即可。 注意耳机旁边的闪烁灯; 用手指盖住它,屏幕就会变黑。
此时环境光传感器的 API 显然是私有的。
There's a lot of confusion between the proximity sensor and the ambient light sensor. The iPhone has both. The Touch does not have a proximity sensor, making it a poor choice for user input. It would be a bad idea anyway since Apple isn't obligated to locate it in the same place in future devices; you aren't supposed to know or care where it is.
The proximity sensor works by pulsing an infrared LED and measuring the amount of reflectance. You can see this using your iSight camera (most digital cameras are sensitive to IR.) Just launch Photo Booth, initiate a call (or play a voicemail) on the phone and point it at your iSight camera. Note the flashing light next to the earpiece; cover it with your finger and the screen will go black.
The ambient light sensor's API is evidently private at this point.
只是为了更新,这是可能的。
正如 benzado 指出的那样,您可以使用:
Just to update, this is possible.
As benzado points out, you can use:
没有用于此目的的公共 API。
There is no public API for this.
iPhone 3.0 正式支持接近传感器。 查看文档中的
UIDeviceproximityMonitoringEnabled
。In iPhone 3.0 there is official support for the proximity sensor. Have a look at
UIDevice proximityMonitoringEnabled
in the docs.如果您的目标不是 AppStore,您可以在此处阅读我的文章,了解如何访问这些内容:
接近传感器: http://iphonedevwiki.net/index.php/AppleProxShim
环境光传感器:http:// iphonedevwiki.net/index.php/AppleISL29003
If you aren't aiming for the AppStore, you can read my articles here on getting access to those:
Proximity Sensor: http://iphonedevwiki.net/index.php/AppleProxShim
Ambient Light Sensor: http://iphonedevwiki.net/index.php/AppleISL29003
显然,如果状态栏处于横向方向,接近传感器将永远不会打开。
即如果你打电话:
[UIApplication共享应用程序].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
您将不再收到“proximity:ON”通知。
这肯定会发生在 OS 3.0 上,我无法在 2.X 设备上测试它,因为我没有带有接近传感器的设备。
这似乎是一个错误。
回答于 2009 年 7 月 22 日 5:49
Kevin Lambert
我也遇到过这个问题。 我花了很长时间才弄清楚接近传感器不工作的真正原因。 当方向为 UIInterfaceOrientationLandscapeLeft 或 UIInterfaceOrientationLandscapeRight 时,接近传感器不起作用; 在纵向模式下效果很好。 我的 iPhone 是 iPhone 4S(iOS SDK 5.0)。
Evidently the proximity sensor will never turn on if the status bar is in landscape orientation.
i.e. if you call:
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
You will no longer get proximity:ON notifications.
This definitely happens on OS 3.0, I can't test it on a 2.X device since I don't have one with a proximity sensor.
This seems like a bug.
answered Jul 22 '09 at 5:49
Kevin Lambert
I've encoutered this problem too. It took me a long time to figure out the real reason of why the proximity sensor is not working. When orientation is UIInterfaceOrientationLandscapeLeft or UIInterfaceOrientationLandscapeRight, proximity sensor does not work; while in portrait mode it works well. My iPhone is iPhone 4S (iOS SDK 5.0).
这些接近传感器基本上是导体矩阵。 垂直“电线”是薄绝缘体一侧的轨道,水平“电线”位于另一侧。 交叉点起到电容器的作用。 您的手指带有静电荷,因此每个结点的电容会随着距离的不同而变化。 FET 放大信号并偏置设置阈值。 实际上,电路比这更复杂,因为它必须检测相对变化并抑制噪声。
但无论如何,传感器网格告诉您的是,已感测到场效应,并且该场效应是指尖大小且位于显示器表面上的物体的特征。 计算电容性扰动的质心(可能由硬件),并将坐标(大概)报告为端口上的数字,最有可能通过中断引起设备操作系统的注意。 在像 iPhone 这样性感的设备中,可能会有最后十几个位置的缓冲区,以便它可以计算出方向和速度。 也许这些也是由硬件计算的,并在同一端口上以数字形式呈现。
Those proximity sensors are basically a matrix of conductors. The vertical "wires" are tracks on one side of a thin sheet of insulator, the horizontal ones are on the other side. The intersections function as capacitors. Your finger carries an electrostatic charge, so capacitance of each junction varies with proximity. FETs amplify the signal and biasing sets a threshold. In practice the circuit is more complex than that because it has to detect a relative change and reject noise.
But anyway, what the sensor grid tells you is that a field effect has been sensed, and that field effect is characteristic of object about the size of a fingertip and resting on the surface of the display. The centroid of the capacitive disturbance is computed (probably by hardware) and the coordinates are (presumably) reported as numbers on a port most likely brought to the attention of the device OS by an interrupt. In something as sexy as an iPhone there's probably a buffer of the last dozen or so positions so it can work out direction and speed. Probably these are also computed by hardware and presented as numbers on the same port.
@Dipak Patel & @Coderer
您可以在以下位置下载工作代码
http://spazout.com/google_cheats_independent_iphone_developers_screwed
它有一个 UIApplication 中未记录方法的 approximationStateChanged 的有效实现。
希望这可以帮助。
@Dipak Patel & @Coderer
You can download working code at
http://spazout.com/google_cheats_independent_iphone_developers_screwed
It has a working implementation of proximityStateChanged a undocumented method in UIApplication.
Hope this helps.
为了关闭屏幕,可以想象使用多个传感器来确定是否应该关闭屏幕。 Cryptognome 描述的红外接近传感器与 Peter Wone 描述的触摸屏传感器相结合,可以判断 iPhone 是否靠近你的脸(或其他带有轻微电荷的物体),或者它是否非常靠近你的物体。 -动画。
To turn the screen off it's conceivable that more than one sensors is used to figure out if the screen should be turned off or not. The IR proximity sensor described by Cryptognome in conjunction with the Touch screen sensor described by Peter Wone could work out if the iphone is being held close to your face (or something else with a slight electric charge) or if its just very close to something in-animate.