How to solve CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]?

泪湿孤枕 提交于 2019-11-30 08:35:16

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

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

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;        
} 

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.

For me it was caused by the toView in this code being nil:

    [UIView transitionFromView:self.fromView
                        toView:self.toView
                      duration:0.6
                       options:(currentPage > toPage ? UIViewAnimationOptionTransitionCurlDown : UIViewAnimationOptionTransitionCurlUp)
                    completion:^(BOOL finished) {
                        if (finished) {
                        }
                    }

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:

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.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!