hai, I use an accelerometer to rotate uiimageview through device orientation, like UIInterfaceOrientationLandscapeRight etc. if I do not use the orientation of the device, (if I put the iphone on the table, the accelerometer should work at a certain angle. The device is in UIInterfaceOrientationPortrait), how can I do this? I rotate the image through the center of this image, but I could not understand in which corner it rotates, does it rotate in the center (as the origin)? ( I want a graphical view with a start ), if I want to stop rotation at a certain angle, how can I do this? code: can anyone 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); } } }
senthilmuthu
source share