0

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]当设备方向为 UIDeviceOrientationFaceDown 时,我正在使用获取通知。

除非设备方向被锁定,否则它工作得很好。

有没有办法使用 Core Motion Framework Gyroscope 来实现相同的行为......?

4

1 回答 1

1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.motionUpdatesQueue = [NSOperationQueue new];
    self.motionUpdatesQueue.maxConcurrentOperationCount = 1;
    self.motionManager = [CMMotionManager new];
    [self.motionManager startDeviceMotionUpdatesToQueue:self.motionUpdatesQueue withHandler:^(CMDeviceMotion *motion, NSError *error) {
        [self handleMotion:motion error:error];
    }];
    return YES;
}

- (void)handleMotion:(CMDeviceMotion *)motion error:(NSError *)error {
    double diff = fabs(1.0 - motion.gravity.z);
    if(diff < .1) {
        NSLog(@"FaceDown");
    } else {
        NSLog(@"non FaceDown");
    }
}
于 2013-11-11T13:20:10.080 回答