【发布时间】:2015-02-18 10:51:52
【问题描述】:
我有一个UIView,其中包含一些点,我通过CLLocationManager根据磁力计的读数使其旋转,如下所示:
@interface PresentationVC () {
float initialBearing;
}
@end
@implementation PresentationVC
- (void)viewDidLoad {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startUpdatingHeading];
[self.locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManager Delegate
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
if(initialBearing == 0) {
initialBearing = newHeading.magneticHeading;
}
NSLog(@"Magnetic Heading: %f", newHeading.magneticHeading);
viewMap.transform = CGAffineTransformMakeRotation(degreesToRadians(initialBearing - newHeading.magneticHeading));
}
@end
其中viewMap 是UIView。
上面的代码有效,但我希望UIView的变换设置为0度/弧度,即CGAffineTransformMakeRotation(0)。目前初始设置为当前方位角,例如157度。
我尝试在上面的代码中使用initialBearing 来计算偏移角度,但它最初仍然旋转到一个角度。我错过了什么?
另外,我不能旋转 360 度;当我转近 180 度时,CGAffineTransformMakeRotation() 会反弹旋转。如何在不弹跳的情况下旋转完整的 360 度旋转? (我猜是关于弧度的问题)
【问题讨论】:
-
似乎没问题,这是您的代码,它工作正常(“红色”视图)dl.dropboxusercontent.com/u/19438780/testHeading.zip
-
非常感谢您的演示项目!最后是我的
degreeToRadians()出现故障。请参阅下面的答案!
标签: ios objective-c cllocationmanager cgaffinetransform magnetometer