如何解决CALayerInvalidGeometry',原因:'CALayer位置包含NaN:[nan nan]? [英] How to solve CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]?

查看:652
本文介绍了如何解决CALayerInvalidGeometry',原因:'CALayer位置包含NaN:[nan nan]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个错误,它在应用程序启动时崩溃。
这是我得到的错误:

I have an error where it crash the application when it is starting up. This is the error that i got:

*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
*** First throw call stack:
(0x250b022 0x2709cd6 0x24b3a48 0x24b39b9 0x217ec0d 0x2174f55 0x158f3f7 0xbc74e 0xbe512 0xbfa26 0xbe4ad 0x224ffda 0x224f956 0x224e449 0x224ab9a 0x24df970 0x247f1c1 0x2442967 0x2441d84 0x2441c9b 0x2c0a7d8 0x2c0a88a 0x1559626 0x2aed 0x2a65)
terminate called throwing an exception

我尝试使用异常断点并且它没有显示代码的哪一部分出错。它只在此时停止-0xbc74e:movl $ 0,%eax-

i tried using Exception breakpoint and it doesn't show which part of the code has gone wrong.It only stop at this point -0xbc74e: movl $0, %eax-

我该如何解决?请帮忙。

How can i solve it? Please help.

*编辑

我找到了抛出异常的部分,但我看不出有什么问题

I found the part which throws the exception but i can't see what is wrong

- (void)viewDidLoad {
[super viewDidLoad];
[self.activityView startAnimating];
self.mapView.layerDelegate = self;
self.mapView.touchDelegate = self;
self.mapView.calloutDelegate = self;

NSURL *mapUrl = [NSURL URLWithString:kTiledMapServiceURL];
AGSTiledMapServiceLayer *tiledLyr = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:mapUrl];
[self.mapView addMapLayer:tiledLyr withName:@"Tiled Layer"];
        .
        .
        .
}
- (void)mapViewDidLoad:(AGSMapView *)mapView {

AGSEnvelope *envelope = [[AGSEnvelope alloc]initWithXmin:29757.610204117 ymin:40055.0379682464 xmax:29884.6992302249 ymax:40236.6028660071 spatialReference:self.mapView.spatialReference];

//call method to set extent, pass in envelope
[self.mapView zoomToEnvelope:envelope animated:YES];

self.mapView.callout.width = 195.0f;
self.mapView.callout.accessoryButtonHidden = YES;

[self.mapView.gps start];
[self.mapView centerAtPoint:self.mapView.gps.currentPoint animated:YES];  

[self.activityView stopAnimating];
self.activityView.hidden = YES;

}

此行导致错误 self.mapView.layerDelegate = self; 默认调用方法 mapViewDidLoad

This line is causing the error self.mapView.layerDelegate = self; which by default call the method mapViewDidLoad

推荐答案

我认为发生此错误是因为执行的图层具有以下格式的框架:

I think this error occurs because the layer which is executed has frame in this form:

图层框架== {{inf, inf},{0,0}}

Layer frame == {{inf, inf}, {0, 0}}

这里inf是下限。它的数字集。

Here inf is infimum. Its set of numbers.

因此,避免此类问题的解决方案只是在返回图层之前创建条件。
喜欢:

So the solution to avoid this kind of issue just create condition before return of layer. Like as:

if (layer.frame.size.width ==0 || layer.frame.size.height ==0 ) {
    return [self simpleLayer];
}else{
    return layer;        
} 

简单图层如下所示:

-(CALayer *)simpleLayer{
    CALayer *layer = [[CALayer alloc] init];
    [layer setFrame:CGRectMake(0, 0, 10, 10)];
    [layer setHidden:TRUE];
    return layer;
}

此条件解决了我的问题。尝试一下。

This condition solved my issue. Try it.

这篇关于如何解决CALayerInvalidGeometry',原因:'CALayer位置包含NaN:[nan nan]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆