2012-07-18 45 views
12

Tôi gặp lỗi khi xảy ra sự cố khi ứng dụng khởi động. Đây là lỗi mà tôi đã nhận:Cách giải quyết CALayerInvalidGeometry ', lý do:' Vị trí CALayer chứa NaN: [nan nan]?

*** 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 

tôi đã cố gắng sử dụng ngoại lệ breakpoint và nó không hiển thị mà một phần của mã đã biến wrong.It chỉ dừng lại ở điểm -0xbc74e này: movl $ 0,% eax -

Tôi có thể giải quyết nó bằng cách nào? Hãy giúp tôi.

* chỉnh sửa

tôi thấy phần mà ném ngoại lệ, nhưng tôi không thể nhìn thấy những gì là sai

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

} 

Dòng này gây ra lỗi self.mapView.layerDelegate = self; mà theo mặc định gọi phương thức mapViewDidLoad

+1

ai biết làm thế nào để giải quyết? – sihao

Trả lời

4

Tôi nghĩ rằng lỗi này xảy ra do lớp được thực hiện có khung trong biểu mẫu này:

Lớp frame == {{inf, inf}, {0, 0}}

Ở đây, inf là tối ưu. Tập số của nó.

Vì vậy, giải pháp để tránh loại vấn đề này chỉ tạo điều kiện trước khi trả lại lớp. Giống như như:

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

đâu lớp đơn giản là giống như:

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

Tình trạng này giải quyết vấn đề của tôi. Thử nó.

+7

Cảm ơn bạn đã trả lời. Nhưng tôi không thể tìm thấy phần nào bị lỗi. tôi có thể đặt mã ở đâu? lời khuyên nào? – sihao

-1

Tôi biết câu hỏi này không phải là rất gần đây nhưng tôi chỉ muốn đưa ra một câu trả lời. Dù sao, tôi đoán bạn mapViewAGSMapView và bạn đã khởi tạo nó theo cách này:

self.mapView = [[[AGSMapView alloc] init] autorelease]; 

Bây giờ, tôi nghĩ tốt hơn, nếu không phải là cách duy nhất đúng, để khởi tạo nó được sử dụng initWithFrame. Mặc dù tôi không chắc chắn tại sao, mapView bị hỏng nếu bạn sử dụng init để khởi tạo.

Hy vọng điều này sẽ hữu ích.

1

Đối với tôi nó là do toView trong mã này là con số không:

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