Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I rotate an image in response to the iPhone's accelerometer?
    text
    copied!<p>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) ? (<strong>i want graphical representation with origin</strong>)if i want to stop rotation in particular angle,how can i do it?the code : anyone can help me...?</p> <pre><code>- (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 &gt;= -2.25 &amp;&amp; self.angle &lt;= -0.25) { if(deviceOrientation != UIInterfaceOrientationPortrait) { deviceOrientation = UIInterfaceOrientationPortrait; self.updatingIsEnabled =YES; self.foamView.center = CGPointMake(center.x,center.y); } } else if(self.angle &gt;= -1.75 &amp;&amp; self.angle &lt;= 0.75) { if(deviceOrientation != UIInterfaceOrientationLandscapeRight) { deviceOrientation = UIInterfaceOrientationLandscapeRight; self.updatingIsEnabled =YES; } } else if(self.angle &gt;= 0.75 &amp;&amp; self.angle &lt;= 2.25) { if(deviceOrientation != UIInterfaceOrientationPortraitUpsideDown) { deviceOrientation = UIInterfaceOrientationPortraitUpsideDown; self.updatingIsEnabled =YES; self.foamView.center = CGPointMake(center.x,center.y); } } else if(self.angle &lt;= -2.25 || self.angle &gt;= 2.25) { if(deviceOrientation != UIInterfaceOrientationLandscapeLeft) { deviceOrientation = UIInterfaceOrientationLandscapeLeft; self.updatingIsEnabled =YES; self.foamView.center = CGPointMake(center.x,center.y); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload