質問

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

役に立ちましたか?

解決

- (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");
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top