Question

I'm using the [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] to get notifications for when the device orientation is UIDeviceOrientationFaceDown.

It works great except for when device orientation is locked.

Is there any way to implement the same behavior using the Core Motion Framework Gyroscope ... ?

Était-ce utile?

La solution

- (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");
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top