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

前端 未结 3 907
逝去的感伤
逝去的感伤 2020-12-30 03:38

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 \'CALayerI         


        
相关标签:
3条回答
  • 2020-12-30 04:20

    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.

    0 讨论(0)
  • 2020-12-30 04:37

    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) {
                            }
                        }
    
    0 讨论(0)
  • 2020-12-30 04:38

    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.

    0 讨论(0)
提交回复
热议问题