是否有框架或示例代码显示如何用于UIAccelerometer
控制屏幕级别,类似于气泡级别应用程序?
我意识到我需要像这样使用它:
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 > 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);
}
}
我如何使用来根据角度从中心向左或向右angleInDegrees
移动?UIView
我上面的尝试不是很成功。