●  什么是传感器
●  传感器是一种感应\检测装置, 目前已经广泛应用于智能手机上

●  iPhone5中内置的传感器有

●  运动传感器\加速度传感器\加速计(Motion/Accelerometer Sensor)

●  环境光传感器(Ambient Light Sensor)

●  距离传感器(Proximity Sensor)

●  磁力计传感器(Magnetometer Sensor)

●  内部温度传感器(Internal Temperature Sensor)

●  湿度传感器(Moisture Sensor)

●  陀螺仪(Gyroscope)

传感器总结

距离传感器的使用:

// 开启距离感应功能
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
// 监听距离感应的通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(proximityChange:)
name:UIDeviceProximityStateDidChangeNotification
object:nil];

- (void)proximityChange:(NSNotificationCenter *)notification {
if ([UIDevice currentDevice].proximityState == YES) {
NSLog(@"某个物体靠近了设备屏幕"); // 屏幕会自动锁住
} else {

NSLog(@"某个物体远离了设备屏幕"); // 屏幕会自动解锁

}
}

//打开距离感应功能

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. // 1.开启距离传感器(注意: 默认情况距离传感器是关闭的)
// [UIApplication sharedApplication].proximitySensingEnabled = YES;
// 只要开启之后, 就开始实时监听
[UIDevice currentDevice].proximityMonitoringEnabled = YES; // 2.当监听到有物体靠近设备时系统会发出通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil]; }
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
} // 当监听到有物体靠近设备时调用
- (void)proximityStateDidChange:(NSNotification *)note
{
// NSLog(@"%@", note);
if( [UIDevice currentDevice].proximityState)
{
NSLog(@"有物体靠近");
}else
{
NSLog(@"物体离开");
}
} @end

IOS UIDevice距离传感器(打开 关闭)的更多相关文章

  1. IOS研究院之打开照相机与本地相册选择图片(六)

    原创文章如需转载请注明:转载自雨松MOMO程序研究院本文链接地址:IOS研究院之打开照相机与本地相册选择图片(六) Hello 大家好 IOS的文章好久都木有更新了,今天更新一篇哈. 这篇文章主要学习 ...

  2. CentOS7使用firewalld打开关闭防火墙与端口(转载)

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disabl ...

  3. fopen(),fclose() 打开/关闭文件

    打开/关闭/刷新流 1. fopen() 打开流 功能: 1)fopen()打开由 path指定的一个文件. 2)fdopen()获取一个先有的文件描述符,并使一个标准的I/O流与该描述相结合.此函数 ...

  4. activity的打开关闭动画

    Activity的打开关闭或者说相互跳转之间可以设置动画的.默认的打开关闭直接消失或出现,比较不优美,但是有的手机Rom对这个默认做了修改,比如红米HM1,默认的就是新页面自右向左滑动出现,自左向右滑 ...

  5. 关于学习CentOS7使用firewalld打开关闭防火墙和端口

    1.firewalld简介 firewalld是centos7的一大特点,主要有两个优点:一是支持动态更新,不需要重启服务:二就是加入了防火墙的“zone”概念. firewalld有图形界面和工具界 ...

  6. XamarinSQLite教程Xamarin.iOS项目中打开数据库文件

    XamarinSQLite教程Xamarin.iOS项目中打开数据库文件 以下是打开MyDocuments.db数据库的具体操作步骤: (1)将Mac电脑上的MyDocuments.db数据库移动到W ...

  7. CentOS7使用httpd apache 和firewalld打开关闭防火墙与端口

    Centos7 使用systemctl 工具操作命令 systemctl 是Centos7的服务管理工具中的主要工具 ,它融合之前service和chkconfig的功能于一体 一.httpd的设置 ...

  8. 根据python上下文管理,写一个在读文件内容前后自动打开关闭文件的程序

    利用上下文管理实现读f文件前后自动打开关闭文件#在本目录创建f文件,内容写monkey代码如下 import contextlib #导入模块1 @contextlib.contextmanager# ...

  9. appium关于当前网络情况测试,实现打开关闭网络(python3.4版)

    appium关于当前网络情况测试,实现打开关闭网络(不需要root测试机) # python from appium.webdriver.connectiontype import Connectio ...

随机推荐

  1. java 简单的des加密示例

    1.加密结果 包含 : 对int加密 .对string加密.对byte[]加密. 10-09 18:33:32.484 7617-7617/com.example.tt.downtest D/Ciph ...

  2. 转 UTL_FILE Throws ORA-29284 Or ORA-29283 When Attempting To READ File

    APPLIES TO: PL/SQL - Version 9.2.0.8 and laterInformation in this document applies to any platform.* ...

  3. linux 命令之重定向

    linux 重定向及部分命令 一,重定向讲解: 1> 标准输出重定向 覆盖原有内容 慎用!!!!!! 1>> 标准输出追加重定向 追加内容 2> 错误输出重定向 只输出错误信息 ...

  4. Unity 代码控制游戏对象是父物体的第多少个子对象

    一个canvas下的游戏对象,排列顺序越往下,渲染顺序就越靠后,就会覆盖在先前的图形上.也就是说,运行游戏后,物体的渲染顺序是一个一个计算的. Transform.SetSiblingIndex(in ...

  5. 详解http之post

    详解http之post 首先,我们先看看jquery中的post方法的使用: $.ajax({ url:'api/bbg/goods/get_goods_list_wechat', data:{ , ...

  6. TT8509: PL/SQL execution terminated; PLSQL_TIMEOUT exceeded

    TT8509: PL/SQL execution terminated; PLSQL_TIMEOUT exceeded plsql_timeout连接超时,解决办法: ODBC pl/sql选项卡 修 ...

  7. temp脚本

    !/bin/bash source ${HOME_DIR}/script/ideploy_dm.inc source ${HOME_DIR}/script/comm_lib home_dir=$(cd ...

  8. nyoj 211——Cow Contest——————【floyd传递闭包】

    Cow Contest 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1.. ...

  9. Linux VFS机制简析(二)

    Linux VFS机制简析(二) 接上一篇Linux VFS机制简析(一),本篇继续介绍有关Address space和address operations.file和file operations. ...

  10. python 将excel转换成字典,并且将字典写到txt文件里

    # -*- coding: utf-8 -*- #python2.7 import sys reload(sys) sys.setdefaultencoding('utf-8') from pyexc ...