我想添加批註和覆蓋到一個mapview,但它隨機崩潰。這是一個EXC_BAD_ACCESS錯誤,但殭屍並沒有告訴我任何東西。它說它在CG :: Path :: apply_transform(CGAffineTransform const &)上崩潰。我到處尋找爲什麼發生這種情況,但無法找到它。當我添加覆蓋到mkmapview的應用程序崩潰
我在ib中創建mapview並讓代表和一切設置正確。它有時會工作,然後隨機崩潰。 我使用的是手勢識別添加的註釋和覆蓋
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[self.mapView addGestureRecognizer:doubleTap];
和
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateRecognized){
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
CLLocationCoordinate2D touchMapCoordinate =
[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
//add pin where user touched down...
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = touchMapCoordinate;
//[pa setTitle:@"title"];
[mapView addAnnotation:pa];
MKCircle* circle=[MKCircle circleWithCenterCoordinate:touchMapCoordinate radius:500];
[mapView addOverlay:circle];
}
}
和每個觀點:
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay
{
if ([overlay isKindOfClass:[MKCircle class]]) {
MKCircleView* circleView = [[MKCircleView alloc] initWithOverlay:overlay];
circleView.strokeColor = [UIColor redColor];
circleView.lineWidth = 1.0;
circleView.fillColor = [UIColor blackColor];
circleView.alpha=.5;
return circleView;
}
else
return nil;
}
- (MKAnnotationView *)mapView:(MKMapView *)localmapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if (![annotation isKindOfClass:[MKUserLocation class]]) {
static NSString *AnnotationIdentifier = @"Annotation";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)[localmapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if (!pinView)
{
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.animatesDrop = YES;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
return nil;
}
是否有更好的方法來添加註釋/與用戶交互疊加到地圖上?我在這段代碼中做錯了什麼?它似乎畫圈的大部分,但然後崩潰...有一些特殊的伎倆mapviews?
爲什麼它的價值我幾乎完全相同的代碼,我經歷了完全相同的間歇性崩潰。這肯定是由MKMapView addOverlay引起的:似乎發生在任意時間。它沒有鏈接到已添加的疊加層數量。如果你解決了這個問題,請在這裏添加一個答案,我也會這樣做。 – Undistraction
1ndivisible的帖子在這裏(http://stackoverflow.com/questions/8266950/debugging-crash-in-coregraphics-mapkit)涵蓋了同樣的崩潰。它是5.0特定的。 – cbowns
我想我遇到了同樣的錯誤,但也看到了這條消息:「錯誤:地址不包含指向對象文件中某個節的節」 –