How do I adjust CMMotionManager data for orientation under iOS 8?

前端 未结 2 1709
生来不讨喜
生来不讨喜 2021-01-25 02:49

My application uses CMMotionManager to track device motion, but iOS always returns device motion data in the standard device orientation (home button at the bottom).

To

2条回答
  •  醉话见心
    2021-01-25 02:58

    I couldn't find a way to directly calculate the transform, so instead I changed my code to calculate set the transform manually when a willRotateToInterfaceOrientation: message is received in my view controller, like this:

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        CGAffineTransform transform;
        switch (toInterfaceOrientation) {
            case UIInterfaceOrientationLandscapeLeft:
                transform = CGAffineTransformMake(
                    0, -1,
                    1, 0,
                    0, 0);
                break;
    
            case UIInterfaceOrientationLandscapeRight:
                transform = CGAffineTransformMake(
                    0, 1,
                    -1, 0,
                    0, 0);
                break;
    
            case UIInterfaceOrientationPortraitUpsideDown:
                transform = CGAffineTransformMake(
                    -1, 0,
                    0, -1,
                    0, 0);
                break;
    
            case UIInterfaceOrientationPortrait:
                transform = CGAffineTransformIdentity;
                break;
        }
        self.motionTransform = transform;
    }
    

提交回复
热议问题