この問題を解決しました。accelerometer's
デバイスの向きが の場合でも回転を取得するために、回転を検出してみましたOFF
。プロジェクトに追加CoreMotion.framerwork
します。次に、にインポートCMMotionManager.h
しますviewController
。にviewDidLoad
、次のコードを追加します。
self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.accelerometerUpdateInterval = 1;
if ([self.motionManager isAccelerometerAvailable])
{
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[self.motionManager startAccelerometerUpdatesToQueue:queue withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
float xx = -accelerometerData.acceleration.x;
float yy = accelerometerData.acceleration.y;
float angle = atan2(yy, xx);
// could fire a custom shouldAutorotateToInterfaceOrientation-event here.
if(angle >= -2.25 && angle <= -0.75)
{
if(_deviceOrientation != UIInterfaceOrientationPortrait)
{
_deviceOrientation = UIInterfaceOrientationPortrait;
}
}
else if(angle >= -0.75 && angle <= 0.75)
{
if(_deviceOrientation != UIInterfaceOrientationLandscapeRight)
{
_deviceOrientation = UIInterfaceOrientationLandscapeRight;
}
}
else if(angle >= 0.75 && angle <= 2.25)
{
if(_deviceOrientation != UIInterfaceOrientationPortraitUpsideDown)
{
_deviceOrientation = UIInterfaceOrientationPortraitUpsideDown;
}
}
else if(angle <= -2.25 || angle >= 2.25)
{
if(_deviceOrientation != UIInterfaceOrientationLandscapeLeft)
{
_deviceOrientation = UIInterfaceOrientationLandscapeLeft;
}
}
});
}];
} else
NSLog(@"not active");