标签:ios
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); }]; }];
标签:ios
原文地址:http://blog.csdn.net/rainlesvio/article/details/40783157