ios 如何解决CALayerInvalidGeometry',原因:'CALayer position contains NaN: [nan nan]?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11533120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to solve CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]?
提问by sihao
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
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-
我尝试使用异常断点,并没有显示这部分代码在这一点上-0xbc74e已经wrong.It唯一的一站:MOVL $ 0%eax-
How can i solve it? Please help.
我该如何解决?请帮忙。
*edit
*编辑
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;
}
This line is causing the error self.mapView.layerDelegate = self;
which by default call the method mapViewDidLoad
此行导致错误self.mapView.layerDelegate = self;
,默认情况下调用该方法mapViewDidLoad
回答by Nilesh Tripathi
I think this error occurs because the layer which is executed has frame in this form:
我认为发生此错误是因为执行的层具有这种形式的框架:
Layer frame == {{inf, inf}, {0, 0}}
层框架 == {{inf, inf}, {0, 0}}
Here inf is infimum. Its set of numbers.
这里 inf 是下界。它的一组数字。
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;
}
Where simple layer is like as :
简单层就像这样:
-(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.
这个条件解决了我的问题。尝试一下。
回答by Andrew Bennett
For me it was caused by the toView in this code being nil:
对我来说,这是由此代码中的 toView 为零引起的:
[UIView transitionFromView:self.fromView
toView:self.toView
duration:0.6
options:(currentPage > toPage ? UIViewAnimationOptionTransitionCurlDown : UIViewAnimationOptionTransitionCurlUp)
completion:^(BOOL finished) {
if (finished) {
}
}
回答by yoninja
I know this question is not very recent but I just want to give an answer. Anyway, I'm guessing your mapView
is of AGSMapView
and you have initialized it this way:
我知道这个问题不是最近出现的,但我只是想给出一个答案。无论如何,我猜你mapView
是的AGSMapView
并且你已经这样初始化了:
self.mapView = [[[AGSMapView alloc] init] autorelease];
Now, I think the better, if not the only correct way, to initialize it is using initWithFrame
. Though I'm not sure why, mapView
is broken if you use init
for the initialization.
现在,我认为更好的,如果不是唯一正确的方法,初始化它是使用initWithFrame
. 虽然我不确定为什么,但mapView
如果您init
用于初始化,则会损坏。
Hope this helps.
希望这可以帮助。