CMDeviceMotion使用

CMDeviceMotion使用

by 吴雪莹

manager = [[CMMotionManager alloc] init];
ViewController *__weak weakSelf=self;
// 1
if(manager.deviceMotionAvailable){
    manager.deviceMotionUpdateInterval=0.01f;
    [manager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue]
         withHandler:^(CMDeviceMotion*data,NSError*error){
             double rotation=atan2(data.gravity.x,data.gravity.y)-M_PI;
             weakSelf.imageView.transform=CGAffineTransformMakeRotation(rotation);
             }];
}
// 2
NSOperationQueue *queue = [[NSOperationQueue alloc] init];[manager startDeviceMotionUpdatesToQueue:queue
   withHandler:^(CMDeviceMotion *data, NSError *error) {
       
       [[NSOperationQueue mainQueue] addOperationWithBlock:^{
           double rotation=atan2(data.gravity.x,data.gravity.y)-M_PI;
           weakSelf.imageView.transform=CGAffineTransformMakeRotation(rotation);
       }];
   }];


版权声明:本文博客原创文章。博客,未经同意,不得转载。

posted @ 2015-08-12 18:30  hrhguanli  阅读(573)  评论(0编辑  收藏  举报