2016-05-23 10 views

答えて

0

を取得するためのいくつかの方法を見つけることができます。 このライブラリをチェックアウトhere

0

あなたは、現在のデバイスの向きや姿勢の変化あなたはこのためにCoreMotionを使用することができますhere

+0

このdoesnの 'tの仕事、画面回転ロック、UIDevice.currentDevice()の向きは、前の状態なかれ場合であり、我々は回転動作にこれをキャプチャすることはできません時間。 – zhiyi

+0

CoreMotionが役立ちます – zhiyi

0

XCoderのおかげで、coreMotionが私を助けました。

そして、私のコードは次のとおりです。

- (void)startMotionManager{ 
    if (_motionManager == nil) { 
     _motionManager = [[CMMotionManager alloc] init]; 
    } 
    _motionManager.deviceMotionUpdateInterval = 1/2.0; 
    if (_motionManager.deviceMotionAvailable) { 
     NSLog(@"Device Motion Available"); 
     [_motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] 
              withHandler: ^(CMDeviceMotion *motion, NSError *error){ 
      [self performSelectorOnMainThread:@selector(handleDeviceMotion:) withObject:motion waitUntilDone:YES]; 
     }]; 
    } else { 
     NSLog(@"No device motion on device."); 
     [self setMotionManager:nil]; 
    } 
} 

- (void)handleDeviceMotion:(CMDeviceMotion *)deviceMotion { 
    double x = deviceMotion.gravity.x; 
    double y = deviceMotion.gravity.y; 
    if (fabs(y) >= fabs(x)) { 
     if (y >= 0) { 
      self.deviceOrientation = UIDeviceOrientationPortraitUpsideDown; 
     } else { 
      self.deviceOrientation = AVCaptureVideoOrientationPortrait; 
     } 
    } else { 
     if (x >= 0) { 
      self.deviceOrientation = UIDeviceOrientationLandscapeRight; 
     } 
     else { 
      self.deviceOrientation = UIDeviceOrientationLandscapeLeft; 
     } 
    } 
} 
関連する問題