我正在制作一个每5度旋转一次的指南针,但问题是当用户旋转设备超过5度时我会同时得到几个响应,并且旋转设备的方法将被调用几次,在最后一个完成之前,它没有给指南针一个平滑的方式。如何在最后一个完成后旋转指南针?
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
if (newHeading.headingAccuracy > 0) {
/* Rotate the compass to the selected degree */
[UIView animateWithDuration:1.0f animations:^{
[self.compassImageView rotateByDegree:degree clockWise:YES];
}];
}
}
答案 0 :(得分:1)
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
// [manager stopUpdatingHeading];
double rotation = newHeading.magneticHeading * 3.14159 / 180;
[_compass_image setTransform:CGAffineTransformMakeRotation(-rotation)];
}