Frage

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 ... ?

War es hilfreich?

Lösung

- (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");
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top