hai , i use accelerometer to rotate uiimageview through device orientation like UIInterfaceOrientationLandscapeRight,etc. if i dont use device orientation,(if i put iphone on the table , accelerometer must work in particular angle.The device is in UIInterfaceOrientationPortrait)how can i do it? i rotate the image through center of that imageview ,but i could not understand in which angle it is rotated ,is it rotating based on the center(as origin) ? (i want graphical representation with origin)if i want to stop rotation in particular angle,how can i do it?the code : anyone can help me...?
- (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);
}
}
}