iPhone의 ProximityState를 감지하여이를 수행 할 수 있습니다. [UIDevice currentDevice]
싱글 톤을 사용하여 proximityMonitoringEnabled
을 YES
으로 설정하십시오. proximityState 속성을 통해 근접 정보에 액세스 할 수 있습니다.
[[UIDevice currentDevice]proximityState];
아이폰이 센서는 통화 중에 귀에 넣어 화면이 꺼집니다있다, AFAIK 그 적외선 센서입니다. 액세스 할 수 있습니다.
편집 : 다음 코드를 사용하여이를 수행 할 수도 있습니다. UIDeviceOrientationFaceDown The device is held parallel to the ground with the screen facing downwards.
(iPhone이 객체에 닿았는지 여부를 알고 싶다면 객체에 접촉했는지 여부에 관계없이) 기기의 근접 상태를 감지합니다.
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
-(void)detectOrientation;{
switch ([[UIDevice currentDevice] orientation]) {
case UIDeviceOrientationPortrait:
{
NSLog(@"portrait");
}
break;
case UIDeviceOrientationPortraitUpsideDown:
{
NSLog(@"portraitUpSideDown");
}
break;
case UIDeviceOrientationLandscapeLeft:
{
NSLog(@"landscapeLeft");
}
break;
case UIDeviceOrientationLandscapeRight:
{
NSLog(@"landscapeRight");
}
break;
case UIDeviceOrientationFaceDown:
{
NSLog(@"facedown!!");
}
break;
default:
break;
}
}
}
편집 : 의견에 질문에 답하십시오.
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleProximityChangeNotification:) name:UIDeviceProximityStateDidChangeNotification object:nil];
다음 방법을
-(void)handleProximityChangeNotification{
if([[UIDevice currentDevice]proximityState]){
NSLog(@"...");
}
}
얼굴을 아래로 향하게 할 때, 물건 즉 표를 아래로 향하게합니다. 아니면 공중에서 얼굴을 마주 치지 않습니까? – geminiCoder
테이블과 같은 모든 물체를 아래로 향하게합니다.이 경우 – Rox
은 근위 검열기를 사용하십시오. 전화기가 귀에 붙었을 때이를 감지하는 가벼운 센서. http://learningiphoneprogramming.com/pdf/The_Sensors_in_your_iPhone.pdf – geminiCoder