문제

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