如何在ios中实现基于加速度计的摆动画

时间:2014-05-20 18:14:05

标签: ios cgaffinetransform uiaccelerometer

Hello Everyone我正在实现基于加速度计的摆动画。 但它给出了奇怪的行为。下面是我的代码。 请帮我找到我错的地方。

#import "DemoViewController.h"

@interface DemoViewController ()

@end

@implementation DemoViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIAccelerometer* theAccel=[UIAccelerometer sharedAccelerometer];
    theAccel.updateInterval=1/50.0f;
    theAccel.delegate=self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
    CGFloat x= acceleration.x;
    self.imPendulum.transform=CGAffineTransformRotate(self.imPendulum.transform,-x);
}
@end

0 个答案:

没有答案