【发布时间】:2009-06-05 07:49:35
【问题描述】:
hai,我使用加速度计通过 UIInterfaceOrientationLandscapeRight 等设备方向旋转 uiimageview。如果我不使用设备方向,(如果我将 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);
}
}
}
【问题讨论】:
标签: iphone