你好,我正在使用加速度计来通过设备方向旋转UIImageView,例如UIInterfaceOrientationLandscapeRight等。如果我不使用设备方向(如果我把iPhone放在桌子上,加速度计必须以特定角度工作。设备处于UIInterfaceOrientationPortrait),我该怎么做?我通过图像视图的中心旋转图像,但我无法理解它旋转的角度是多少(是否以原点为中心旋转)?如果我想停止在特定角度旋转,我该怎么做?代码如下:请问有人可以帮我吗?
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
rollingX = (acceleration.x * 0.1) + (rollingX * (1.0 - 0.1));
rollingY = (acceleration.y * 0.1) + (rollingY * (1.0 - 0.1));
float xx = -rollingX;
float yy = rollingY;
float angle = atan2(yy, xx);
self.angle += M_PI / 2.0;
if(self.angle >= -2.25 && self.angle <= -0.25)
{
if(deviceOrientation != UIInterfaceOrientationPortrait)
{
deviceOrientation = UIInterfaceOrientationPortrait;
self.updatingIsEnabled =YES;
self.foamView.center = CGPointMake(center.x,center.y);
}
}
else if(self.angle >= -1.75 && self.angle <= 0.75)
{
if(deviceOrientation != UIInterfaceOrientationLandscapeRight)
{
deviceOrientation = UIInterfaceOrientationLandscapeRight;
self.updatingIsEnabled =YES;
}
}
else if(self.angle >= 0.75 && self.angle <= 2.25)
{
if(deviceOrientation != UIInterfaceOrientationPortraitUpsideDown)
{
deviceOrientation = UIInterfaceOrientationPortraitUpsideDown;
self.updatingIsEnabled =YES;
self.foamView.center = CGPointMake(center.x,center.y);
}
}
else if(self.angle <= -2.25 || self.angle >= 2.25)
{
if(deviceOrientation != UIInterfaceOrientationLandscapeLeft)
{
deviceOrientation = UIInterfaceOrientationLandscapeLeft;
self.updatingIsEnabled =YES;
self.foamView.center = CGPointMake(center.x,center.y);
}
}
}