小编d0n*_*n13的帖子

过滤指南针读数

我正在使用罗盘标题来旋转MKMapView.旋转是有点生涩,所以我试图像iPhone上的谷歌地图那样过滤它(或者似乎做了一些诡计).

我试图使用移动平均公式来过滤iphone指南针的读数,但它在359和0之间的交叉处失败,因为它从35x开始向后平均到0并导致地图向后旋转,因为它从西方.

任何想法最好的方法是过滤这些数据,使其从359回到零,并保持滚动平均值.

代码在这里:

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
static float xd=0;
static float k = 0.22;

// Moving average formula
xd = k * xd + (1.0 - k) * newHeading.magneticHeading;

NSLog(@"%0.2f : %0.2f", newHeading.magneticHeading, xd);    
[map setTransform:CGAffineTransformMakeRotation((-1 * xd * M_PI) /180)];}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

iphone filter moving-average mkmapview compass-geolocation

5
推荐指数
1
解决办法
2231
查看次数

+ animateWithDuration:动画:完成:在模拟器下崩溃

更新

我也遇到了同样的问题,调用+animateWithDuration:animations:completion:在设备上正常工作但在模拟器上崩溃.

[UIView animateWithDuration:0.5 
                 animations:^{
                     NSLog(@"Begin");
                 }
                 completion:^(BOOL finished){
                     NSLog(@"End");
                 }];
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我没有访问任何其他对象,它仍然会因EXC_BAD_ACCESS而崩溃.

更新2

它似乎只崩溃,如果你传递一个blockcompletion:传递NULL正常工作.

[UIView animateWithDuration:0.5 
                 animations:^{
                     NSLog(@"Begin");
                 }
                 completion:NULL];
Run Code Online (Sandbox Code Playgroud)

原始问题

我一直在使用手机进行开发,主要是因为我使用的是一个没有为英特尔编译的库,但现在已经切换回模拟器以加快速度.

当我使用UIView animateWithDuration并且不得不在我的代码中暂时将它们注释掉时,我会遇到相应的崩溃问题.他们在手机上工作正常.我正在使用最新的SDK 4.3.1(几乎)并编译4.0以上版本.

任何想法为什么会崩溃?

    [UIView animateWithDuration:0.5 animations:^ {
    mapTableOverlay.alpha = 0.8;} completion:^(BOOL finished){}];
Run Code Online (Sandbox Code Playgroud)

调用上面的行时获取EXC_BAD_ACCESS.感谢帮助....

cocoa-touch core-animation uiview ios4

5
推荐指数
1
解决办法
1344
查看次数