- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想检测 UIDeviceOrientationFaceDown。我怎样才能做到这一点???实际上,当我的 iPhone 脸朝下放在平面上时,我想执行一些操作。这怎么可能???请帮助我做到这一点。
我有这段代码,但不知道在哪里以及如何应用这段代码
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
BOOL getOrientationUpdates = [[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications];
NSLog(@"will receive orientation notifications: %@", getOrientationUpdates?@"YES":@"NO");
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
如果有任何教程,请建议我
提前致谢,非常欢迎您提供宝贵的帮助和建议。
最佳答案
您可以通过检测 iPhone 的 ProximityState 来完成此操作。使用 [UIDevice currentDevice]
单例,将 proximityMonitoringEnabled
设置为 YES
。您可以通过 proximityState 属性访问邻近信息。
[[UIDevice currentDevice]proximityState];
iPhone 有一个传感器,当您在通话过程中将它放在耳朵上时,它会关闭屏幕,据我所知,这是一个红外线传感器。您可以访问它。
编辑:您也可以使用以下代码完成它。 UIDeviceOrientationFaceDown
(不管它是否接触到任何物体)如果你想知道 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;
}
}
}
编辑:回答评论中的问题。在您的 viewDidLoad 中添加这一行
[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(@"...");
}
}
关于iphone - UIDeviceOrientation 在 iphone 中面朝下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12090408/
我试图找出 iPhone 在模拟器中的方向,而不是使用 UIDevice 方向属性将其提供给我,我只是得到 UIDeviceOrientationUnknown。 这个属性在模拟器中不起作用吗?发生这
为了接收 UIDeviceOrientation 更改通知,必须做两件事: 在 UIDevice 上调用 beginGeneratingDeviceOrientationNotifications 注
我想检测设备的当前方向。 所以,我用了一行代码 注意:即使我没有注册它也能给我方向感 -(IBAction) deviceOrientationChanged:(id) sender{ NSL
UIDeviceOrientationUnknown Orientation 的用途是什么?订阅有关设备方向的通知时,什么时候接收此消息比根本不接收任何消息更有利? 我只是想理解为什么这个方向甚至包含
我有以下代码根据方向填充 View 。这总是返回景观。 - (void)setData:(BCPlaylist *)list { UIDeviceOrientation orientation =
我目前正在制作一款游戏,如果您先拿起手机,那么您就输了。因此,我有一个方向观察器来检查手机何时被拿起(纵向)。但是,每当我锁定手机然后解锁时,方向观察器会自动认为手机处于纵向模式,即使手机正面朝上。
我想检测 UIDeviceOrientationFaceDown。我怎样才能做到这一点???实际上,当我的 iPhone 脸朝下放在平面上时,我想执行一些操作。这怎么可能???请帮助我做到这一点。 我
我收到以下代码的上述编译器警告。我了解界面和设备方向之间的区别,但不确定如何修改以删除警告。有人可以帮忙吗? - (void)willRotateToInterfaceOrientation:(UII
我正在尝试检测某个 ViewController 中的方向变化。我使用通知和自定义功能。对于 iPhone 7(运行 iOS 10.2),每次通知更改时都会调用旋转功能。但是在使用 iPhone 6(
我正在使用 Xcode 5.0.2 并在尝试编译我的 Objective-C 代码时收到以下警告: Implicit conversion from enumeration type 'enum UI
在 Xcode 中,我在 FBConnect 的以下行中收到警告: _orientation = [UIApplication sharedApplication].statusBarOrientat
完整警告: Implicit conversion from enumeration type 'UIInterfaceOrientation' to different enumeration ty
我是一名优秀的程序员,十分优秀!