Hai, ich benutze Beschleunigungsmesser, um uiimageview durch Geräteausrichtung wie UIInterfaceOrientationLandscapeRight, etc zu drehen. wenn ich nicht Geräteausrichtung verwende, (wenn ich iphone auf den Tisch setze, muss Beschleunigungsmesser in einem bestimmten Winkel arbeiten. Das Gerät ist in UIInterfaceOrientationPortrait) Wie kann ich es tun? Ich drehe das Bild durch das Zentrum dieses Bildausschnitts, aber ich konnte nicht verstehen, in welchem Winkel es gedreht wird, dreht es sich auf der Mitte (als Ursprung)? (Ich möchte eine grafische Darstellung mit Ursprung) Wenn ich die Rotation in bestimmten Winkel stoppen möchte, wie kann ich es tun? Der Code: jeder kann mir helfen ...?Wie kann ich ein Bild als Antwort auf den Beschleunigungsmesser des iPhones drehen?
- (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);
}
}
}