我正在开发一个应用程序,当设备定位关闭时,我将在景观模式下捕获图像。我正在使用GPUImageStillCamera捕捉图像。但我在旋转图像上遇到了问题。问题是,当我捕获图像在景观模式与设备旋转关闭和保存在画廊,然后打开设备旋转和图像必须旋转与设备的方向。但在纵向模式下保持装置时图像处于景观状态,如果保持装置在景观中,则图像旋转为UpsideDown。
Note
当拍摄到与设备旋转有关的图像旋转时,图像旋转非常完美。当设备旋转关闭时,只有在景观模式下才会出现图像问题。我尝试过许多解决方案,比如这一个。但对我不起作用。
任何帮助都将不胜感激。谢谢
发布于 2015-03-05 11:09:24
我有办法解决这个问题。我尝试检测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");https://stackoverflow.com/questions/28780806
复制相似问题