title: Using UIAccelerometer to create a level app
body: <p>Is there a framework or example code out there that shows how to use <code>UIAccelerometer</code> to control an onscreen level, similar to the bubble level apps?</p>
  
  <p>I realize I need to use it like:</p>
  
  <pre><code>UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
  accel.delegate = self;
  accel.updateInterval = 1.0f/50.0f;
  
  - (void)accelerometer:(UIAccelerometer *)acel didAccelerate:(UIAcceleration *)aceler
  {
      // get angle in radians
      float angle = atan2(aceler.x, aceler.y);
      // convert to degrees
      float angleInDegrees = (angle * 180/M_PI);
  
      NSLog(@"%.0f degrees",angleInDegrees);
  
      if (angleInDegrees &gt; 90) {
          self.levelIndicator.center = CGPointMake(self.cachedLevel.x+angleInDegrees-90, self.cachedLevel.y);
      } else {
          self.levelIndicator.center = CGPointMake(self.cachedLevel.x-angleInDegrees+90, self.cachedLevel.y);
      }
  
  }
  </code></pre>
  
  <p>How could I use the <code>angleInDegrees</code> to move a simple <code>UIView</code> left or right from center based on what the angle is? My attempt above wasn't very successful.</p>