当我将叠加层添加到mkmapview时,应用崩溃 [英] App crashing when I add overlay to mkmapview
问题描述
我正在尝试向地图视图添加注释和叠加层,但是它会随机崩溃.这是EXC_BAD_ACCESS错误,但僵尸没有告诉我任何事情.它说它在CG :: Path :: apply_transform(CGAffineTransform const&)上崩溃.我到处都在寻找为什么发生这种情况,但无法查明.
I am trying to add annotations and overlays to a mapview but it crashes randomly. It is an EXC_BAD_ACCESS error, but zombies doesn't tell me anything. It says it is crashing on CG::Path::apply_transform(CGAffineTransform const&). I have looked everywhere for why this is happening but can't pinpoint it.
我正在ib中创建mapview,并正确设置了委托和所有内容.它有时会工作,然后随机崩溃. 我正在使用手势识别器添加注释和覆盖
I am creating the mapview in ib and have the delegates and everything set up right. It will work sometimes and then crash randomly. I am using a gesture recognizer to add the annotations and overlay
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有一些特殊的技巧吗?
Is there a better way to add annotations/overlays to maps with user interaction? Am I doing something wrong in this code? It appears to draw most of the circle but then crashes... Is there some special trick to mapviews?
推荐答案
我一直得到完全相同的错误:
I've been getting the exact same error:
CG :: Path :: apply_transform(CGAffineTransform const&)将命中一条测试指令,并给我一个EXC_BAD_ACCESS
CG::Path::apply_transform(CGAffineTransform const&) will hit a test instruction and give me an EXC_BAD_ACCESS
当在地图上双击以放大MKCircle时,会特别发生这种情况.
This specifically occurs when using a double click on the map to zoom in on an MKCircle.
我无法确切地说出这句话,但据我所知,仅当您使用双击缩放时,模拟器上才会出现此问题,我从未能够从实际设备中引起错误,或者通过使用Option +单击以放大模拟器.
I can't say this definitively, but to the best of my knowledge this problem only occurs on the simulator when you use a double click to zoom, I've never been able to cause the error from an actual device, or by using option+click to zoom on the simulator.
因此,这时我已将其提交到模拟器错误"下,并留在那儿.
So at this point I've filed this under "simulator bug" and left it at that.
如果您确实发现了相反的情况,请告诉我,因为这确实使我感到困扰,因为我没有明确知道这是否是我的应用程序中存在的我无法正确复制的错误.
If you do discover anything to the contrary, please let me know because it really bothers me not explicitly knowing whether or not this is a bug existing in my app that I just can't properly reproduce.
最初将其标记为不是答案",所以我将提供更多信息来支持我的猜想.
This was flagged initially as "not an answer" so I'll provide a little bit more information supporting my conjecture.
基本上,在我们两个场景中,一个手势都在触发MKCircleView的重新渲染,我强烈怀疑的是,由于模拟器能够生成某种形式的手势,而该手势无法由用户实际创建设备,当手势得到处理时,在链下某处会有失败的期望.
Basically in both of our scenarios a gesture is firing the re-rendering of the MKCircleView, what I strongly suspect is that since the simulator is able to generate some kind of gesture which can't be created from a user on the actual device, there is a failed expectation somewhere down the chain while that gesture gets handled.
这篇关于当我将叠加层添加到mkmapview时,应用崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!